@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;900&display=swap');

:root {
  --bg-light: #f5f7fb;
  --bg-light-card: #ffffff;
  --text-light: #0f172a;
  --text-light-muted: #64748b;
  --border-light: rgba(15, 23, 42, 0.08);

  --bg-dark: #07091a;
  --bg-dark-card: #0d1126;
  --text-dark: #eef2ff;
  --text-dark-muted: #94a3b8;
  --border-dark: rgba(255, 255, 255, 0.08);

  --bg-purple: #120821;
  --bg-purple-card: #1a0f30;
  --text-purple: #f3e8ff;
  --text-purple-muted: #c4b5fd;
  --border-purple: rgba(167, 139, 250, 0.18);
  --accent-purple-theme: #a855f7;

  /* NoVa brand */
  --nova-1: #6366f1;
  --nova-2: #8b5cf6;
  --nova-3: #06b6d4;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --success: #16a34a;
  --error: #ef4444;
  --warning: #f59e0b;
}

html, body {
  --bg: var(--bg-dark);
  --bg-card: var(--bg-dark-card);
  --text: var(--text-dark);
  --text-muted: var(--text-dark-muted);
  --border: var(--border-dark);
}
html.light-mode, html.light-mode body {
  --bg: var(--bg-light); --bg-card: var(--bg-light-card);
  --text: var(--text-light); --text-muted: var(--text-light-muted); --border: var(--border-light);
}
html.purple-mode, html.purple-mode body {
  --bg: var(--bg-purple); --bg-card: var(--bg-purple-card);
  --text: var(--text-purple); --text-muted: var(--text-purple-muted); --border: var(--border-purple);
  --accent: var(--accent-purple-theme); --accent-hover: #9333ea;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: 'Tajawal', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background-color .35s ease, color .35s ease;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99,102,241,.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(6,182,212,.15), transparent 60%),
    radial-gradient(800px 600px at 50% 120%, rgba(139,92,246,.18), transparent 60%),
    var(--bg);
}
html.light-mode body {
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(99,102,241,.12), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(6,182,212,.10), transparent 60%),
    var(--bg);
}

.container { max-width: 1080px; margin: 0 auto; padding: 24px; }

/* ========== Header / Brand ========== */
header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px; padding: 18px 22px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255,255,255,.04), rgba(255,255,255,.01));
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-wrap: wrap; gap: 16px;
}
html.light-mode header {
  background: linear-gradient(135deg, rgba(255,255,255,.85), rgba(255,255,255,.6));
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 240px; }

.logo {
  width: 52px; height: 52px; border-radius: 16px;
  background: conic-gradient(from 180deg at 50% 50%, var(--nova-1), var(--nova-2), var(--nova-3), var(--nova-1));
  display: grid; place-items: center;
  color: white; font-size: 24px; font-weight: 900;
  box-shadow: 0 10px 30px rgba(124,58,237,.45), inset 0 0 20px rgba(255,255,255,.15);
  position: relative; overflow: hidden;
  animation: novaSpin 12s linear infinite;
}
.logo::after {
  content: ""; position: absolute; inset: 3px; border-radius: 13px;
  background: var(--bg-card);
}
.logo i { position: relative; z-index: 1;
  background: linear-gradient(135deg, var(--nova-1), var(--nova-3));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
@keyframes novaSpin { to { transform: rotate(360deg); } }

h1 {
  font-size: 28px; font-weight: 900; line-height: 1.1; letter-spacing: -.5px;
  background: linear-gradient(135deg, #818cf8, #c084fc 50%, #22d3ee);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.lead { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.theme-toggle {
  display: flex; gap: 6px; padding: 6px;
  background: var(--bg-card); border-radius: 12px; border: 1px solid var(--border);
}
.theme-btn {
  width: 38px; height: 38px; border: none; border-radius: 9px;
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: all .25s; font-size: 16px; display: grid; place-items: center;
}
.theme-btn:hover, .theme-btn.active {
  background: linear-gradient(135deg, var(--nova-1), var(--nova-2));
  color: white; transform: translateY(-1px);
}

/* ========== Cards ========== */
.wrap {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
  border-radius: 18px; padding: 24px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
  backdrop-filter: blur(8px);
}
html.light-mode .wrap {
  background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.85));
  box-shadow: 0 4px 24px rgba(15,23,42,.05);
}

h3 {
  font-size: 18px; font-weight: 700;
  margin: 0 0 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
h3 i { color: var(--nova-2); }

.input-section { display: grid; gap: 14px; }

textarea, input[type=file], select {
  flex: 1; min-width: 200px; padding: 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-family: inherit; font-size: 15px;
  transition: all .2s;
}
textarea:focus, select:focus {
  outline: none; border-color: var(--nova-2);
  box-shadow: 0 0 0 4px rgba(139,92,246,.15);
}
textarea { resize: vertical; min-height: 130px; line-height: 1.7; }

/* ========== Buttons ========== */
button {
  background: linear-gradient(135deg, var(--nova-1), var(--nova-2));
  border: none; padding: 12px 20px; border-radius: 12px;
  color: white; font-weight: 700; cursor: pointer;
  font-size: 14px; transition: all .25s; font-family: inherit;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(99,102,241,.25);
}
button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(124,58,237,.4);
  filter: brightness(1.05);
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); box-shadow: none;
}
button.secondary:hover:not(:disabled) { background: var(--border); }
button.success { background: linear-gradient(135deg, #10b981, #059669); }

/* ========== Status ========== */
.status {
  padding: 14px 16px; background: var(--bg-card);
  border-radius: 12px; color: var(--text-muted);
  font-size: 14px; margin: 14px 0;
  display: none; border-right: 4px solid transparent;
  animation: slideIn .3s ease;
  word-wrap: break-word;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(10px);} to { opacity:1; transform: translateX(0);} }
@keyframes fadeBlurIn { from { opacity:0; filter: blur(10px); transform: translateY(20px);} to { opacity:1; filter: blur(0); transform: translateY(0);} }
@keyframes slideUp { from { opacity:0; transform: translateY(20px);} to { opacity:1; transform: translateY(0);} }

.status.loading { color: var(--warning); display: block; border-color: var(--warning); }
.status.success { color: var(--success); display: block; border-color: var(--success); }
.status.error { color: var(--error); display: block; border-color: var(--error); }

pre {
  white-space: pre-wrap; word-wrap: break-word;
  background: var(--bg-card); padding: 18px; border-radius: 12px;
  overflow: auto; max-height: 460px; font-size: 15px;
  line-height: 1.9; border: 1px solid var(--border); color: var(--text);
  font-family: 'Tajawal', sans-serif;
}

.keypoints-list { background: var(--bg-card); padding: 16px; border-radius: 12px; border: 1px solid var(--border); display: grid; gap: 10px; }
.keypoint-item {
  padding: 14px; border-radius: 10px; line-height: 1.7; font-size: 15px;
  background: linear-gradient(135deg, rgba(99,102,241,.10), rgba(139,92,246,.06));
  border-right: 3px solid var(--nova-2);
}

/* ========== Quiz ========== */
.quiz-container { display: grid; gap: 20px; }
.progress-container { margin-bottom: 16px; }
.progress-info { display:flex; justify-content:space-between; margin-bottom:8px; font-size:13px; color: var(--text-muted); }
.progress-bar { width: 100%; height: 10px; background: var(--bg-card); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--nova-1), var(--nova-3)); border-radius: 999px; transition: width .4s ease; }
.quiz-q { border: 1px solid var(--border); padding: 22px; border-radius: 14px; background: var(--bg-card); }
.quiz-q-text { margin-bottom: 16px; font-weight: 700; font-size: 17px; line-height: 1.6; }
.quiz-choices { display: grid; gap: 10px; }
.choice-btn {
  text-align: right; padding: 14px 16px;
  background: rgba(139,92,246,.08);
  border: 2px solid rgba(139,92,246,.25);
  color: var(--text); font-size: 15px; cursor: pointer;
  border-radius: 10px; transition: all .2s; box-shadow: none; font-weight: 500;
}
.choice-btn:hover:not(:disabled) { background: rgba(139,92,246,.18); border-color: var(--nova-2); transform: translateX(-3px); }
.choice-btn.correct { background: rgba(16,185,129,.18); border-color: var(--success); color: #10b981; }
.choice-btn.incorrect { background: rgba(239,68,68,.18); border-color: var(--error); color: #ef4444; }
.choice-btn:disabled { cursor: default; }
.explanation { margin-top: 12px; padding: 12px; background: rgba(34,211,238,.10); border-right: 3px solid var(--nova-3); border-radius: 8px; font-size: 14px; color: #67e8f9; line-height: 1.6; }
.quiz-results { text-align: center; padding: 36px; background: linear-gradient(135deg, rgba(16,185,129,.10), rgba(6,182,212,.08)); border-radius: 14px; border: 1px solid rgba(16,185,129,.3); }
.result-score { font-size: 64px; font-weight: 900; background: linear-gradient(135deg, #10b981, #06b6d4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.result-message { font-size: 22px; margin: 8px 0 18px; font-weight: 700; }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.flex { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; }

footer {
  margin-top: 28px; font-size: 13px; color: var(--text-muted);
  text-align: center; padding: 16px;
}
footer .heart { color: var(--error); }

.result-section { display: none; }
.result-section.active { display: block; animation: fadeBlurIn .5s ease; }

/* ========== Drop zone ========== */
.drop-zone {
  border: 2px dashed var(--border); border-radius: 14px;
  padding: 44px 20px; text-align: center; cursor: pointer;
  transition: all .3s; background: var(--bg-card); position: relative;
}
.drop-zone:hover { border-color: var(--nova-2); background: rgba(139,92,246,.05); }
.drop-zone.dragover { border-color: var(--nova-2); background: rgba(139,92,246,.10); box-shadow: 0 0 30px rgba(139,92,246,.3); transform: scale(1.01); }
.drop-zone-icon { font-size: 52px; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--nova-1), var(--nova-3));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.drop-zone-text { font-size: 16px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.drop-zone-hint { font-size: 13px; color: var(--text-muted); }
.drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.file-info { display: none; align-items: center; gap: 12px; padding: 14px; background: rgba(16,185,129,.10); border: 1px solid rgba(16,185,129,.3); border-radius: 12px; margin-top: 12px; }
.file-info.active { display: flex; animation: slideUp .3s ease; }
.file-info i { color: var(--success); font-size: 20px; }
.file-info-text { flex: 1; }
.file-info-name { font-weight: 700; color: var(--text); }
.file-info-size { font-size: 12px; color: var(--text-muted); }
.file-info-remove { background: transparent; border: none; color: var(--error); cursor: pointer; padding: 8px; border-radius: 6px; box-shadow: none; }
.file-info-remove:hover { background: rgba(239,68,68,.1); transform: none; box-shadow: none; }

/* ========== Tabs ========== */
.tools-section { display: none; }
.tools-section.active { display: block; animation: fadeBlurIn .5s ease; }
.tabs-header { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn { padding: 12px 18px; background: transparent; border: none; color: var(--text-muted); font-weight: 600; cursor: pointer; transition: all .25s; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; font-family: inherit; font-size: 14px; box-shadow: none; }
.tab-btn:hover { color: var(--text); background: rgba(139,92,246,.05); transform: none; }
.tab-btn.active { color: var(--nova-2); border-bottom-color: var(--nova-2); background: rgba(139,92,246,.08); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: slideUp .3s ease; }

/* Teacher */
.teacher-mode { background: var(--bg-card); border-radius: 12px; padding: 22px; border: 1px solid var(--border); }
.lesson-card { background: linear-gradient(135deg, rgba(99,102,241,.06), rgba(139,92,246,.04)); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.lesson-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.lesson-title { font-weight: 700; font-size: 16px; color: var(--nova-2); display: flex; align-items: center; gap: 8px; }
.lesson-toggle { color: var(--text-muted); transition: transform .3s; }
.lesson-card.expanded .lesson-toggle { transform: rotate(180deg); }
.lesson-body { display: none; }
.lesson-card.expanded .lesson-body { display: block; animation: slideUp .3s ease; }
.objectives-list { margin: 12px 0; padding: 12px; background: rgba(16,185,129,.08); border-radius: 8px; }
.objective-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; display: flex; gap: 8px; }
.objective-item:last-child { border-bottom: none; }
.objective-item i { color: var(--success); margin-top: 4px; }
.questions-section { margin-top: 14px; }
.question-item { padding: 14px; background: rgba(6,182,212,.08); border-radius: 8px; margin-bottom: 8px; }
.question-type { font-size: 11px; padding: 3px 10px; background: linear-gradient(135deg, var(--nova-1), var(--nova-2)); color: white; border-radius: 999px; margin-left: 8px; font-weight: 600; }

/* ========== Chat (NoVa) ========== */
.chat-container {
  display: none; position: fixed; bottom: 24px; left: 24px;
  width: 400px; max-width: calc(100vw - 32px); height: 560px; max-height: calc(100vh - 80px);
  background: var(--bg-card); border-radius: 20px; border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  flex-direction: column; z-index: 1000; overflow: hidden;
}
.chat-container.active { display: flex; animation: slideUp .35s ease; }
.chat-header { padding: 16px 18px; background: linear-gradient(135deg, var(--nova-1), var(--nova-2)); color: white; display: flex; justify-content: space-between; align-items: center; }
.chat-header-title { font-weight: 700; display: flex; align-items: center; gap: 10px; }
.chat-header-title .mini-logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: rgba(255,255,255,.2); display: grid; place-items: center;
  font-size: 14px; font-weight: 900;
}
.chat-close { background: rgba(255,255,255,.2); border: none; color: white; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; box-shadow: none; }
.chat-close:hover { background: rgba(255,255,255,.3); transform: none; box-shadow: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.chat-message { max-width: 85%; padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.6; animation: slideUp .2s ease; }
.chat-message.user { background: linear-gradient(135deg, var(--nova-1), var(--nova-2)); color: white; align-self: flex-start; border-bottom-right-radius: 4px; }
.chat-message.bot { background: var(--bg); color: var(--text); align-self: flex-end; border-bottom-left-radius: 4px; border: 1px solid var(--border); }
.chat-message.bot.loading { display: flex; gap: 4px; align-items: center; }
.typing-dot { width: 8px; height: 8px; background: var(--nova-2); border-radius: 50%; animation: typingBounce 1.4s infinite ease-in-out; }
.typing-dot:nth-child(1){animation-delay:-.32s} .typing-dot:nth-child(2){animation-delay:-.16s}
@keyframes typingBounce { 0%,80%,100% { transform: scale(.6); opacity:.5;} 40% { transform: scale(1); opacity:1;} }
.chat-input-container { padding: 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-input { flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--text); font-size: 14px; outline: none; font-family: inherit; }
.chat-input:focus { border-color: var(--nova-2); }
.chat-send { width: 44px; height: 44px; border-radius: 50%; padding: 0; display: grid; place-items: center; }

.chat-toggle-btn {
  position: fixed; bottom: 24px; left: 24px;
  width: 60px; height: 60px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 10px 30px rgba(124,58,237,.5);
  z-index: 999;
  background: linear-gradient(135deg, var(--nova-1), var(--nova-2), var(--nova-3));
  background-size: 200% 200%;
  animation: novaPulse 3s ease infinite;
}
@keyframes novaPulse { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.chat-toggle-btn.hidden { display: none; }

/* Export */
.export-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.export-btn { padding: 10px 16px; font-size: 13px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text); box-shadow: none; }
.export-btn:hover { background: linear-gradient(135deg, var(--nova-1), var(--nova-2)); color: white; border-color: transparent; }

/* Audio */
.audio-controls { display: flex; align-items: center; gap: 12px; padding: 16px; background: var(--bg-card); border-radius: 12px; border: 1px solid var(--border); margin-top: 16px; flex-wrap: wrap; }
.voice-select { padding: 10px 16px; border-radius: 10px; min-width: 150px; }
.audio-player { width: 100%; margin-top: 12px; border-radius: 8px; }

/* Responsive */
@media (max-width: 768px) {
  .container { padding: 14px; }
  h1 { font-size: 22px; }
  .lead { font-size: 12px; }
  .wrap { padding: 16px; }
  .actions { grid-template-columns: 1fr; }
  button { width: 100%; justify-content: center; }
  .theme-toggle { width: 100%; justify-content: center; }
  .theme-btn { flex: 1; }
  .chat-container { width: calc(100vw - 20px); left: 10px; bottom: 10px; height: calc(100vh - 80px); }
  .chat-toggle-btn { left: 14px; bottom: 14px; }
  .tab-btn { padding: 10px 12px; font-size: 12px; }
  pre { font-size: 13px; max-height: 340px; }
  .result-score { font-size: 48px; }
}

/* ========== Language / Settings row (v4) ========== */
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 0 6px;
  border-top: 1px dashed var(--border);
}
.setting-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 220px;
}
.setting-field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.setting-field label i { color: var(--accent); }
.setting-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.setting-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .15);
}
.setting-hint {
  font-size: 11px;
  color: var(--text-muted);
}
html[dir="rtl"] textarea,
html[dir="rtl"] .chat-input { text-align: right; }
