/* ============================================================
   Faisal Teaching App — High-End Clean Design System
   ============================================================ */

:root {
  --primary: #4F46E5;
  --primary-gradient: linear-gradient(135deg, #6366F1 0%, #7C3AED 100%);
  --primary-strong: #4338CA;
  --on-primary: #FFFFFF;
  --secondary: #818CF8;
  --accent: #10B981;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-glass: rgba(255, 255, 255, 0.88);
  --fg: #0F172A;
  --fg-muted: #64748B;
  --border: #E2E8F0;
  --border-soft: #F1F5F9;
  --border-glow: rgba(99, 102, 241, 0.2);
  --danger: #EF4444;
  --ring: #6366F1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 9999px;
  --font-ui: 'Plus Jakarta Sans', 'Nunito', 'Noto Nastaliq Urdu', system-ui, sans-serif;
  --font-urdu: 'Noto Nastaliq Urdu', 'Plus Jakarta Sans', serif;
}

html[data-theme="dark"] {
  --primary: #818CF8;
  --primary-gradient: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
  --primary-strong: #6366F1;
  --on-primary: #0F172A;
  --secondary: #4F46E5;
  --accent: #34D399;
  --bg: #0B0F19;
  --surface: #131B2E;
  --surface-2: #1E293B;
  --surface-glass: rgba(19, 27, 46, 0.9);
  --fg: #F8FAFC;
  --fg-muted: #94A3B8;
  --border: #1E293B;
  --border-soft: #172033;
  --border-glow: rgba(129, 140, 248, 0.25);
  --danger: #F87171;
  --ring: #818CF8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; border: none; outline: none; background: none; }
svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Layout ---------- */
#app { display: flex; height: 100dvh; width: 100vw; overflow: hidden; position: relative; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100dvh; position: relative; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 270px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  transition: margin-inline-start 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

#sidebar.hidden-desktop { margin-inline-start: -270px; }

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.brand-badge svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text .b-main { font-weight: 800; font-size: 15px; line-height: 1.2; color: var(--fg); }
.brand-text .b-sub { font-size: 11px; color: var(--fg-muted); font-weight: 600; }

.close-side-btn { display: none; }

.new-chat-btn {
  margin: 12px 14px 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: #FFFFFF;
  font-weight: 700; font-size: 14.5px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.new-chat-btn:hover { opacity: 0.94; transform: translateY(-1px); }
.new-chat-btn:active { transform: scale(0.97); }

.sidebar-tools {
  padding: 6px 14px;
  display: flex; flex-direction: column; gap: 4px;
  border-bottom: 1px solid var(--border-soft);
}

.side-tool-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 13px; font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.side-tool-btn:hover { background: var(--surface-2); color: var(--fg); }
.side-tool-btn svg { color: var(--primary); }

.history-label {
  padding: 12px 18px 4px;
  font-size: 11px; font-weight: 800; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--fg-muted);
}
.history-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.history-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 3px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font-size: 13px; text-align: start;
  min-height: 40px;
  transition: background 0.15s ease;
}
.history-item:hover { background: var(--surface-2); }
.history-item.active {
  background: var(--surface-2);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--primary);
  color: var(--primary);
}
.history-item .h-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .h-del {
  color: var(--fg-muted); padding: 4px; border-radius: 6px; display: none;
}
.history-item:hover .h-del, .history-item.active .h-del { display: flex; }
.history-item .h-del:hover { color: var(--danger); background: var(--border); }

.sidebar-foot { padding: 10px 14px; border-top: 1px solid var(--border-soft); }
.ghost-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 8px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; color: var(--fg-muted);
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--fg); }
.ghost-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(239, 68, 68, 0.08); }
.ghost-btn.sm { width: auto; padding: 5px 10px; font-size: 12px; }

/* ---------- Topbar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface-glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-brand-badge {
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 15px; color: var(--fg);
}
.tb-badge-txt {
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.topbar-controls { display: flex; align-items: center; gap: 8px; }

.pill-select {
  appearance: none;
  padding: 6px 12px;
  min-height: 36px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 12.5px; font-weight: 700;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease;
}
.pill-select:hover, .pill-select:focus { border-color: var(--primary); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface); color: var(--fg-muted);
  border: 1px solid var(--border);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--primary); border-color: var(--primary); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn.txt { font-size: 13px; font-weight: 700; width: auto; padding: 0 10px; font-family: var(--font-urdu); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.tool-btn { border-color: transparent; background: transparent; }
.icon-btn.tool-btn:hover { background: var(--surface-2); }
.icon-btn.mic-btn { color: var(--primary); }
.icon-btn.mic-btn.listening { background: var(--danger); color: #fff; animation: pulseGlow 1.2s infinite; }

@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

html[data-theme="dark"] .ic-sun { display: block; color: #F59E0B; }
html[data-theme="dark"] .ic-moon { display: none; }
html:not([data-theme="dark"]) .ic-sun { display: none; }
html:not([data-theme="dark"]) .ic-moon { display: block; color: var(--primary); }

/* ---------- Main Chat View ---------- */
#chatScroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#chatInner {
  max-width: 840px;
  margin: 0 auto;
  padding: 24px 18px 140px;
  display: flex; flex-direction: column; gap: 18px;
}

/* Welcome Hero */
#welcome { text-align: center; padding: 3vh 8px 10px; }
.welcome-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 10px; }
.w-badge {
  width: 72px; height: 72px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 24px;
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: var(--shadow-lg);
}
.w-badge svg { width: 38px; height: 38px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: rgba(16, 185, 129, 0.1); color: var(--accent);
  font-size: 11.5px; font-weight: 700; border: 1px solid rgba(16, 185, 129, 0.2);
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.welcome-title {
  font-weight: 800; font-size: 28px;
  margin: 6px 0 4px;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.w-sub { max-width: 580px; margin: 0 auto 20px; color: var(--fg-muted); font-size: 14.5px; font-weight: 500; }

/* Feature Cards Grid */
.feature-cards-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin-bottom: 20px; text-align: start;
}
.feat-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.feat-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.feat-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.feat-icon.scan { background: linear-gradient(135deg, #06B6D4, #3B82F6); }
.feat-icon.voice { background: linear-gradient(135deg, #EC4899, #8B5CF6); }
.feat-icon.formula { background: linear-gradient(135deg, #10B981, #059669); }
.feat-icon.quiz { background: linear-gradient(135deg, #F59E0B, #D97706); }
.feat-text { display: flex; flex-direction: column; }
.feat-title { font-weight: 700; font-size: 13.5px; color: var(--fg); }
.feat-desc { font-size: 11.5px; color: var(--fg-muted); font-weight: 500; }

.section-label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-muted); margin: 16px 0 8px; text-align: start;
}

/* Topic chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.chip {
  padding: 7px 14px; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg); font-size: 13px; font-weight: 600;
  transition: all 0.15s ease; box-shadow: var(--shadow-sm);
}
.chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); transform: translateY(-1px); }

/* Examples */
.examples { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; text-align: start; }
.example-card {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg); font-size: 13px; font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.example-card:hover { border-color: var(--primary); background: var(--surface-2); }
.example-card .ex-ur { font-family: var(--font-urdu); font-size: 12.5px; color: var(--fg-muted); }

/* ---------- Chat Messages ---------- */
.msg { display: flex; gap: 12px; width: 100%; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--fg-muted);
}
.msg.user .msg-avatar { background: var(--primary-gradient); color: #fff; border: none; }
.msg.bot .msg-avatar { background: var(--surface); color: var(--primary); border-color: var(--border-glow); }

.msg-bubble {
  max-width: 84%;
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 18px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); position: relative;
}
.msg.user .msg-bubble {
  background: var(--primary-gradient); color: #FFFFFF;
  border: none; border-bottom-end-radius: 4px;
  box-shadow: var(--shadow);
}
.msg.bot .msg-bubble { border-bottom-start-radius: 4px; }
.msg.error .msg-bubble { border-color: var(--danger); background: rgba(239, 68, 68, 0.05); }

.msg-img { max-width: 100%; max-height: 240px; border-radius: 10px; object-fit: contain; }

.msg-content { word-break: break-word; font-size: 14.5px; line-height: 1.6; }
.msg-content p { margin: 0 0 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 { font-weight: 700; margin: 10px 0 4px; font-size: 16px; }
.msg-content code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13.5px; }
.msg.user .msg-content code { background: rgba(255,255,255,0.2); }
.msg-content pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }

/* KaTeX Boxed result highlight */
.katex-display { margin: 10px 0; overflow-x: auto; padding: 4px 0; }

.msg-actions {
  display: flex; align-items: center; gap: 6px; margin-top: 4px;
  padding-top: 6px; border-top: 1px solid var(--border-soft);
}
.msg-action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--fg-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.msg-action-btn:hover { background: var(--surface-2); color: var(--primary); }

/* Typing dots */
.typing { display: flex; align-items: center; gap: 5px; padding: 6px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary);
  animation: typingDot 1.4s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ---------- Composer Bar ---------- */
#composer {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: var(--surface-glass);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  z-index: 46;
}

#sidebar:not(.hidden-desktop) ~ #main #composer {
  left: 270px;
}

.composer-container { max-width: 840px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }

.composer-row {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 4px 6px 4px 10px;
  box-shadow: var(--shadow); transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-row:focus-within { border-color: var(--primary); box-shadow: var(--shadow-lg); }

#msgInput {
  flex: 1; border: none; outline: none; background: transparent;
  color: var(--fg); font-size: 14.5px; line-height: 1.5;
  resize: none; max-height: 140px; padding: 8px 2px;
}

.send-btn {
  width: 38px; height: 38px; border-radius: 14px; flex-shrink: 0;
  background: var(--primary-gradient); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); transition: transform 0.15s ease, opacity 0.15s ease;
}
.send-btn:hover { opacity: 0.92; transform: scale(1.03); }
.send-btn:active { transform: scale(0.95); }
.send-btn .ic-stop { display: none; }
.send-btn.streaming { background: var(--danger); }
.send-btn.streaming .ic-send { display: none; }
.send-btn.streaming .ic-stop { display: block; }

.composer-hint {
  font-size: 11px; color: var(--fg-muted); text-align: center; font-weight: 500;
}

/* Image Preview */
.img-preview {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  align-self: flex-start;
}
.img-preview img { height: 40px; width: 40px; border-radius: 6px; object-fit: cover; }

/* Voice Banner */
.voice-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--fg); font-size: 13px; font-weight: 600;
}
.voice-wave { display: flex; align-items: center; gap: 3px; height: 14px; }
.voice-wave span {
  width: 3px; height: 100%; background: var(--danger); border-radius: 3px;
  animation: wave 1s infinite ease-in-out;
}
.voice-wave span:nth-child(2) { animation-delay: 0.2s; }
.voice-wave span:nth-child(3) { animation-delay: 0.4s; }
.voice-wave span:nth-child(4) { animation-delay: 0.6s; }

@keyframes wave {
  0%, 100% { height: 20%; }
  50% { height: 100%; }
}

/* ---------- MOBILE BOTTOM DOCK ---------- */
.mobile-dock {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface-glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 10px max(6px, env(safe-area-inset-bottom));
  justify-content: space-around; align-items: center;
  z-index: 45; box-shadow: var(--shadow-lg);
}

.dock-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 8px; border-radius: 10px; color: var(--fg-muted);
  font-size: 10.5px; font-weight: 700; transition: color 0.15s ease;
}
.dock-item svg { width: 20px; height: 20px; }
.dock-item:hover, .dock-item:active { color: var(--primary); }
.dock-item.highlight { color: var(--primary); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100; opacity: 1; transition: opacity 0.2s ease;
}
.modal[hidden] { display: none; opacity: 0; }

.modal-card {
  width: 100%; max-width: 500px; max-height: 88vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalUp 0.2s ease-out;
}
.modal-card.wide { max-width: 680px; }

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

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { font-size: 18px; font-weight: 700; margin: 0; }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--fg); }
.key-row { display: flex; gap: 6px; }
.key-row input {
  flex: 1; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--fg); font-size: 13.5px; outline: none;
}
.key-row input:focus { border-color: var(--primary); }
.field-help { font-size: 11.5px; color: var(--fg-muted); }

.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border-soft);
  display: flex; justify-content: flex-end; gap: 8px;
}
.primary-btn {
  padding: 10px 20px; border-radius: var(--radius-sm);
  background: var(--primary-gradient); color: #fff;
  font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow-sm);
}
.primary-btn:hover { opacity: 0.94; }

.key-status { font-size: 12.5px; font-weight: 600; margin-inline-start: 8px; }
.key-status.ok { color: var(--accent); }
.key-status.bad { color: var(--danger); }

/* Formula Sheet */
.formula-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; border-bottom: 1px solid var(--border-soft); }
.f-tab {
  padding: 6px 12px; border-radius: var(--radius-pill);
  font-size: 12.5px; font-weight: 600; color: var(--fg-muted);
  border: 1px solid var(--border); white-space: nowrap;
}
.f-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.formula-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.f-card {
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 5px;
}
.f-card-title { font-weight: 700; font-size: 13.5px; color: var(--primary); }
.f-card-math { background: var(--surface); padding: 6px; border-radius: 6px; font-size: 13.5px; text-align: center; }
.f-card-ask {
  align-self: flex-end; font-size: 11.5px; font-weight: 700; color: var(--accent);
  display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 5px;
}
.f-card-ask:hover { background: rgba(16, 185, 129, 0.1); }

/* Quiz */
.quiz-card {
  padding: 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px;
}
.quiz-q { font-weight: 700; font-size: 14px; color: var(--fg); }
.quiz-sol { font-size: 13px; color: var(--fg-muted); background: var(--surface); padding: 8px; border-radius: 6px; }

/* Overlay Mobile */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 48; display: none;
}
#overlay.show { display: block; }

/* Mobile Responsive */
@media (max-width: 820px) {
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }
  .close-side-btn { display: flex; }
  
  .header-tool { display: none; }
  .feature-cards-grid { grid-template-columns: repeat(2, 1fr); }
  .examples { grid-template-columns: 1fr; }
  .formula-grid { grid-template-columns: 1fr; }

  #composer { bottom: 58px; padding-bottom: 6px; }
  #chatInner { padding-bottom: 160px; }
  .mobile-dock { display: flex; }
}

/* Small phones: topbar controls sab fit karo, overflow na ho */
@media (max-width: 560px) {
  #topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); gap: 6px; }
  .topbar-left { gap: 6px; }
  .topbar-brand-badge { display: none; }        /* hamburger + content kaafi hai */
  .topbar-controls { gap: 5px; }
  .pill-select { padding: 6px 8px; font-size: 11.5px; min-height: 34px; }
  #levelSelect { max-width: 116px; }
  .icon-btn { width: 34px; height: 34px; }
  .icon-btn.txt { padding: 0 7px; font-size: 12.5px; }
}

@media (max-width: 480px) {
  .welcome-title { font-size: 24px; }
  .w-sub { font-size: 13px; }
  .feature-cards-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .feat-card { padding: 10px; }
}

/* ============================================================
   AUTH SCREEN — Glassmorphism Login / Signup
   ============================================================ */
body.auth-locked #app { display: none; }
body.auth-locked { overflow: hidden; }

#authScreen {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
#authScreen[hidden] { display: none; }

.auth-bg { position: absolute; inset: 0; z-index: -1; }
.auth-hills { width: 100%; height: 100%; display: block; }

.auth-card {
  position: relative;
  width: min(430px, 100%);
  padding: 42px 34px 26px;
  border-radius: 28px;
  background: linear-gradient(160deg, rgba(255,255,255,.22), rgba(255,255,255,.08));
  border: 1.5px solid rgba(255,255,255,.45);
  backdrop-filter: blur(18px) saturate(1.15);
  -webkit-backdrop-filter: blur(18px) saturate(1.15);
  box-shadow: 0 24px 60px rgba(20, 40, 15, .35);
  color: #fff;
  animation: authIn .45s ease both;
}
@keyframes authIn { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }

.auth-lang-btn {
  position: absolute; top: 16px; inset-inline-end: 16px;
  border: 1.5px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.12);
  color: #fff;
  font-weight: 700; font-size: 13px;
  padding: 6px 14px; min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  font-family: 'Noto Nastaliq Urdu', 'Plus Jakarta Sans', sans-serif;
  transition: background .15s ease;
}
.auth-lang-btn:hover { background: rgba(255,255,255,.25); }

.auth-title {
  margin: 0 0 6px;
  font-size: 42px; font-weight: 800; line-height: 1.1;
  text-shadow: 0 2px 12px rgba(0,0,0,.18);
}
.auth-sub {
  margin: 0 0 26px;
  font-size: 15px;
  color: rgba(255,255,255,.92);
}

.auth-field { position: relative; margin-bottom: 16px; }
.auth-field input {
  width: 100%;
  padding: 15px 52px 15px 18px;
  min-height: 52px;
  border-radius: 14px;
  border: 1.5px solid rgba(255,255,255,.55);
  background: rgba(255,255,255,.10);
  color: #fff;
  font-family: inherit; font-size: 15.5px;
  outline: none;
  transition: border-color .15s ease, background .15s ease;
  box-sizing: border-box;
}
#authScreen[dir="rtl"] .auth-field input { padding: 15px 18px 15px 52px; }
.auth-field input::placeholder { color: rgba(255,255,255,.78); }
.auth-field input:focus { border-color: #fff; background: rgba(255,255,255,.18); }
.auth-field > svg, .auth-eye {
  position: absolute; top: 50%; transform: translateY(-50%);
  inset-inline-end: 16px;
  width: 22px; height: 22px;
  color: rgba(255,255,255,.85);
}
.auth-eye {
  border: none; background: none; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
}
.auth-eye svg { width: 22px; height: 22px; }
.auth-eye:hover { color: #fff; }

.auth-remember {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 0 18px;
  font-size: 14.5px; font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.auth-remember input { position: absolute; opacity: 0; pointer-events: none; }
.auth-check {
  width: 24px; height: 24px; flex: none;
  border-radius: 7px;
  border: 1.5px solid rgba(255,255,255,.6);
  background: rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  transition: background .15s ease;
}
.auth-check svg { width: 14px; height: 14px; opacity: 0; transition: opacity .12s ease; }
.auth-remember input:checked + .auth-check {
  background: linear-gradient(135deg, #8FBF3F, #27AE60);
  border-color: transparent;
}
.auth-remember input:checked + .auth-check svg { opacity: 1; }
.auth-remember input:focus-visible + .auth-check { outline: 2.5px solid #fff; outline-offset: 2px; }

.auth-error {
  margin: -6px 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(220, 38, 38, .28);
  border: 1.5px solid rgba(255, 120, 120, .65);
  color: #fff;
  font-size: 13.5px; font-weight: 600;
}

.auth-btn {
  width: 100%;
  padding: 16px;
  min-height: 54px;
  border: none; border-radius: 14px;
  background: linear-gradient(100deg, #A6C63B 0%, #4CB050 55%, #27AE60 100%);
  color: #fff;
  font-family: inherit; font-size: 20px; font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(39, 174, 96, .4);
  transition: transform .15s ease, filter .15s ease;
}
.auth-btn:hover { filter: brightness(1.07); }
.auth-btn:active { transform: scale(.97); }
.auth-btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.auth-switch {
  margin: 16px 0 0;
  text-align: center;
  font-size: 15px;
  color: rgba(255,255,255,.92);
}
.auth-switch button {
  border: none; background: none; padding: 2px 4px;
  color: #fff; font-family: inherit; font-size: 15px; font-weight: 800;
  cursor: pointer;
  text-decoration: underline transparent;
  transition: text-decoration-color .15s ease;
}
.auth-switch button:hover { text-decoration-color: #fff; }

.auth-credit {
  margin: 30px 0 0;
  text-align: center;
  font-size: 13px;
  color: rgba(255,255,255,.85);
}

#authScreen.urdu .auth-title,
#authScreen.urdu .auth-sub,
#authScreen.urdu .auth-remember,
#authScreen.urdu .auth-switch,
#authScreen.urdu .auth-error,
#authScreen.urdu .auth-btn,
#authScreen.urdu .auth-field input {
  font-family: 'Noto Nastaliq Urdu', 'Plus Jakarta Sans', sans-serif;
}
#authScreen.urdu .auth-title { font-size: 34px; line-height: 1.6; }
#authScreen.urdu .auth-btn { font-size: 17px; }

@media (max-width: 480px) {
  .auth-card { padding: 34px 22px 22px; border-radius: 24px; }
  .auth-title { font-size: 34px; }
}

/* ---------- Sidebar user chip ---------- */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border-soft);
}
.user-chip-avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
}
.user-chip-avatar svg { width: 18px; height: 18px; }
.user-chip-name {
  flex: 1;
  font-weight: 800; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* [hidden] must always win over class display rules */
.img-preview[hidden], .voice-banner[hidden] { display: none !important; }

/* ============================================================
   ANIMATED AI TEACHER CHARACTER
   ============================================================ */
.teacher-widget {
  position: fixed;
  inset-inline-end: 14px;
  bottom: 128px;
  z-index: 45;
  width: 150px;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.teacher-widget.t-gone { opacity: 0; pointer-events: none; transform: translateY(24px) scale(.9); }
body.auth-locked .teacher-widget, body.auth-locked .teacher-mini { display: none; }

.t-figure { width: 100%; }
.t-figure svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 14px rgba(15,23,42,.22)); }

/* gentle bob */
.t-body { animation: tBob 3.8s ease-in-out infinite; transform-origin: 110px 230px; }
@keyframes tBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* blink */
.t-eye { animation: tBlink 4.6s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes tBlink { 0%, 91%, 96%, 100% { transform: scaleY(1); } 93.5% { transform: scaleY(.08); } }

/* mouth: smile by default, talking ellipse when speaking */
.t-mouth { opacity: 0; transform-box: fill-box; transform-origin: center; }
.teacher-widget.speaking .t-smile { opacity: 0; }
.teacher-widget.speaking .t-mouth { opacity: 1; animation: tTalk .32s ease-in-out infinite alternate; }
@keyframes tTalk { from { transform: scaleY(.35); } to { transform: scaleY(1.05); } }

/* pen arm writing */
.t-pen-arm { transform-box: fill-box; transform-origin: 85% 20%; }
.teacher-widget.writing .t-pen-arm { animation: tWrite .4s ease-in-out infinite alternate; }
@keyframes tWrite { from { transform: rotate(-3.5deg) translate(0, 0); } to { transform: rotate(2.5deg) translate(-4px, 2px); } }

/* sparks visible only while writing */
.t-sparks { opacity: 0; }
.teacher-widget.writing .t-sparks { opacity: 1; animation: tSpark .5s linear infinite; }
@keyframes tSpark { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

/* speech bubble */
.t-bubble {
  pointer-events: auto;
  position: absolute;
  bottom: calc(100% + 2px);
  inset-inline-end: 8px;
  min-width: 150px; max-width: 220px;
  padding: 9px 13px;
  border-radius: 14px;
  border-end-end-radius: 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-lg);
  color: var(--fg);
  font-size: 12.5px; font-weight: 700;
  line-height: 1.5;
  animation: tBubbleIn .25s ease both;
}
.t-bubble.urdu { font-family: var(--font-urdu); font-size: 13px; line-height: 1.9; }
@keyframes tBubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* hide (x) button */
.t-hide-btn {
  pointer-events: auto;
  position: absolute;
  top: 26px; inset-inline-end: 2px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--fg-muted);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .2s ease;
}
.t-hide-btn svg { width: 12px; height: 12px; }
.teacher-widget:hover .t-hide-btn { opacity: 1; }
.t-hide-btn:hover { color: var(--danger); border-color: var(--danger); }

/* mini re-open button */
.teacher-mini {
  position: fixed;
  inset-inline-end: 16px;
  bottom: 132px;
  z-index: 45;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform .15s ease;
}
.teacher-mini:hover { transform: scale(1.08); }
.teacher-mini svg { width: 22px; height: 22px; }

/* speaking state on Listen button */
.msg-action-btn.speaking { color: var(--primary); }
.msg-action-btn.speaking svg { animation: tSpark .6s linear infinite; }

/* settings checkbox row */
.checkbox-field { display: flex; flex-direction: row; align-items: center; gap: 10px; cursor: pointer; }
.checkbox-field input { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; }
.checkbox-field span { font-weight: 700; font-size: 14px; }

@media (max-width: 820px) {
  /* Teacher input bar ke saaf upar rahe, kabhi usay na dhake */
  .teacher-widget { width: 92px; bottom: calc(215px + env(safe-area-inset-bottom)); inset-inline-end: 6px; }
  .t-bubble { min-width: 120px; max-width: 158px; font-size: 11px; }
  .teacher-mini { width: 40px; height: 40px; bottom: calc(220px + env(safe-area-inset-bottom)); }
  .teacher-mini svg { width: 19px; height: 19px; }
}
@media (max-width: 480px) {
  .teacher-widget { width: 78px; bottom: calc(210px + env(safe-area-inset-bottom)); }
  .t-bubble { min-width: 108px; max-width: 140px; }
  .teacher-mini { bottom: calc(214px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .t-body, .t-eye, .t-pen-arm, .t-sparks, .t-mouth { animation: none !important; }
}

/* [hidden] must win over class display rules */
.teacher-mini[hidden], .t-bubble[hidden] { display: none !important; }

/* ============================================================
   USAGE PILL + UPGRADE MODAL (backend / paid mode)
   ============================================================ */
.usage-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; min-height: 34px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--fg); font-size: 12px; font-weight: 800;
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s ease, transform .1s ease;
}
.usage-pill:hover { border-color: var(--primary); }
.usage-pill:active { transform: scale(.95); }
.usage-pill.low { border-color: var(--danger); color: var(--danger); }
.usage-pill.paid {
  background: linear-gradient(100deg, #F59E0B, #EAB308);
  color: #1a1400; border-color: transparent;
}
.usage-pill svg { width: 14px; height: 14px; }

.upgrade-card { text-align: center; max-width: 400px; padding-bottom: 24px; position: relative; }
.upgrade-x { position: absolute; top: 12px; inset-inline-end: 12px; }
.upgrade-crown {
  width: 66px; height: 66px; margin: 8px auto 10px;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #F59E0B, #EAB308);
  color: #fff; box-shadow: 0 10px 26px rgba(234,179,8,.4);
}
.upgrade-crown svg { width: 34px; height: 34px; }
.upgrade-card h2 { margin: 0 0 4px; font-size: 24px; font-family: var(--font-ui); font-weight: 800; }
.upgrade-price { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin-bottom: 10px; }
.up-amt { font-size: 40px; font-weight: 800; color: var(--primary); }
.up-per { font-size: 15px; color: var(--fg-muted); font-weight: 700; }
.upgrade-msg { color: var(--fg-muted); font-size: 14px; margin: 0 0 16px; padding: 0 8px; }
.upgrade-features {
  list-style: none; padding: 0; margin: 0 0 20px; text-align: start;
  display: flex; flex-direction: column; gap: 10px;
}
.upgrade-features li {
  font-size: 14px; font-weight: 600; color: var(--fg);
  background: var(--surface-2); padding: 10px 14px; border-radius: 10px;
}
.upgrade-btn { display: block; width: 100%; text-decoration: none; text-align: center; font-size: 16px; }
.upgrade-note { font-size: 12px; color: var(--fg-muted); margin: 10px 0 0; }

html[dir="rtl"] .upgrade-features { text-align: right; }
