:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-elevated: #22223a;
  --text: #e8e8f0;
  --text-muted: #9898b0;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --border: #2a2a45;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --font: 'Vazirmatn', 'Tahoma', system-ui, sans-serif;
  --lang-color: #6366f1;
  --med-color: #10b981;
  --phil-color: #8b5cf6;
  --lit-color: #f59e0b;
  --sci-color: #3b82f6;
  --quote-color: #ec4899;
  --book-color: #14b8a6;
  --psy-color: #f43f5e;
}

[data-theme="light"] {
  --bg: #f5f5fa;
  --bg-card: #ffffff;
  --bg-elevated: #f0f0f8;
  --text: #1a1a2e;
  --text-muted: #666680;
  --border: #e0e0ee;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  direction: rtl;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.streak-badge {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 80px;
  overflow-y: auto;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: inherit;
  transition: color 0.2s;
}

.nav-item.active { color: var(--primary); }
.nav-item .icon { font-size: 1.35rem; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Module cards on dashboard */
.module-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.module-card:active { transform: scale(0.98); }
.module-card:hover { border-color: var(--primary); }

.module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.module-name {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.module-level {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.progress-bar {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Quiz */
.quiz-option {
  display: block;
  width: 100%;
  text-align: right;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.quiz-option:hover { border-color: var(--primary); }
.quiz-option.correct { border-color: var(--success); background: rgba(34,197,94,0.15); }
.quiz-option.wrong { border-color: var(--danger); background: rgba(239,68,68,0.15); }
.quiz-option.selected { border-color: var(--primary); }

/* Input */
.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus, .textarea:focus { border-color: var(--primary); }
.textarea { min-height: 100px; resize: vertical; }

/* Labels */
.label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-primary { background: rgba(99,102,241,0.2); color: var(--primary); }
.badge-success { background: rgba(34,197,94,0.2); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.2); color: var(--warning); }

/* Skill tree */
.skill-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  min-width: 80px;
  text-align: center;
  font-size: 0.75rem;
}

.skill-node.unlocked { border-color: var(--success); }
.skill-node.locked { opacity: 0.5; }

/* Lists */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.list-item:hover { background: var(--border); }

/* Modal / Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 300;
  animation: fadeIn 0.3s ease;
  box-shadow: var(--shadow);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* XP popup */
.xp-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, var(--primary), #a855f7);
  color: white;
  padding: 20px 30px;
  border-radius: var(--radius);
  font-size: 1.2rem;
  font-weight: 700;
  z-index: 300;
  animation: xpPop 0.6s ease;
  box-shadow: 0 8px 30px rgba(99,102,241,0.4);
}

@keyframes xpPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

/* Section title */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 16px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* Diff highlight for transcription */
.diff-correct { color: var(--success); }
.diff-wrong { color: var(--danger); text-decoration: line-through; }
.diff-missing { color: var(--warning); background: rgba(245,158,11,0.2); padding: 0 2px; border-radius: 2px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 4px;
}

.tab {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: white;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Drug / Philosopher / Author card */
.info-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.info-card h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
}

.info-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.info-label {
  color: var(--text-muted);
  min-width: 90px;
}

/* Responsive */
@media (max-width: 360px) {
  .main-content { padding: 12px; }
  .module-name { font-size: 0.85rem; }
  .btn { padding: 8px 14px; font-size: 0.85rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 10px;
}

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

/* Mission card */
.mission-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mission-card.done {
  opacity: 0.6;
}

.mission-info {
  flex: 1;
}

.mission-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.mission-xp {
  font-size: 0.75rem;
  color: var(--warning);
}

/* Achievement */
.achievement-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.achievement-item.locked { opacity: 0.4; }
.achievement-icon { font-size: 1.5rem; }
.achievement-name { font-weight: 600; font-size: 0.9rem; }
.achievement-desc { font-size: 0.75rem; color: var(--text-muted); }

/* Search */
.search-box {
  position: relative;
  margin-bottom: 14px;
}

.search-box input {
  padding-right: 40px;
}

.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Notes */
.note-area {
  margin-top: 12px;
}

/* Favorite heart */
.fav-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
}

.fav-btn.active { color: #ec4899; }
