/* ===== Base & Variables ===== */
:root {
  --bg: #0a0e27;
  --bg-card: #12183a;
  --text: #e8ecf8;
  --text-muted: #a0a8c8;
  --accent: #7c9cff;
  --accent-glow: #5b7cfa;
  --gold: #f0c75e;
  --success: #4ade80;
  --danger: #f87171;
  --border: rgba(255,255,255,0.08);
  --radius: 16px;
  --font-size: 16px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

body.theme-sepia {
  --bg: #1c1810;
  --bg-card: #2a2418;
  --text: #f5e6c8;
  --text-muted: #c4b89a;
  --accent: #d4a84b;
  --gold: #e8c56a;
}

body.theme-light {
  --bg: #f0f4ff;
  --bg-card: #ffffff;
  --text: #1a1f3a;
  --text-muted: #5a6280;
  --accent: #4a6cf7;
  --gold: #c9a227;
  --border: rgba(0,0,0,0.08);
  --shadow: 0 8px 32px rgba(0,0,0,0.08);
}

body.theme-high-contrast {
  --bg: #000000;
  --bg-card: #111111;
  --text: #ffffff;
  --text-muted: #cccccc;
  --accent: #00ff88;
  --gold: #ffff00;
  --border: rgba(255,255,255,0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: var(--font-size);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ===== Loading ===== */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0e27;
}

.stars-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
  overflow: hidden;
}

.stars-bg::before,
.stars-bg::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: 
    100px 50px white, 200px 150px #aaf, 50px 200px white,
    300px 80px #aaf, 150px 300px white, 400px 200px white,
    80px 400px #aaf, 350px 350px white, 250px 50px white,
    450px 100px #aaf, 20px 100px white, 500px 300px white,
    120px 450px #aaf, 380px 420px white, 60px 30px white;
  animation: twinkle 3s infinite alternate;
}

.stars-bg::after {
  width: 1px;
  height: 1px;
  box-shadow: 
    30px 80px white, 180px 20px #aaf, 320px 250px white,
    90px 320px white, 410px 50px #aaf, 220px 180px white;
  animation-delay: 1.5s;
}

@keyframes twinkle {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

.loading-content {
  position: relative;
  text-align: center;
  z-index: 1;
}

.moon-loader {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f0e6d0, #c9b896);
  margin: 0 auto 20px;
  box-shadow: 0 0 40px rgba(240, 200, 100, 0.4);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.loading-content h1 {
  font-size: 1.8rem;
  color: var(--gold);
  margin-bottom: 8px;
}

.progress-bar {
  width: 200px;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 20px auto 0;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  animation: load 1.8s ease forwards;
}

@keyframes load {
  to { width: 100%; }
}

.hidden { display: none !important; }

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

.app-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--gold);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: rgba(255,255,255,0.1);
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--bg-card);
  z-index: 200;
  transition: left 0.3s ease;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  left: 0;
}

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

.menu-list {
  list-style: none;
  padding: 12px 0;
}

.menu-list li {
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 1rem;
}

.menu-list li:hover,
.menu-list li:active {
  background: rgba(124, 156, 255, 0.15);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

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

/* ===== Main ===== */
#main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 80px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.view {
  display: none;
  animation: fadeIn 0.35s ease;
}

.view.active {
  display: block;
}

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

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-glow));
  color: #fff;
  box-shadow: 0 4px 16px rgba(91, 124, 250, 0.35);
}

.btn.secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ===== Home ===== */
.hero {
  text-align: center;
  padding: 32px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.hero-stars {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(124,156,255,0.15), transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(240,199,94,0.1), transparent 40%);
  pointer-events: none;
}

.hero h2 {
  font-size: 1.5rem;
  margin-bottom: 12px;
  color: var(--gold);
  position: relative;
}

.hero-desc {
  color: var(--text-muted);
  margin-bottom: 24px;
  position: relative;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  position: relative;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px 8px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-num {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

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

.feature-cards {
  display: grid;
  gap: 12px;
}

.feature-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.feature-card:active {
  transform: scale(0.98);
}

.feature-card:hover {
  border-color: var(--accent);
}

.feature-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.feature-card h3 {
  margin-bottom: 6px;
  font-size: 1.1rem;
}

.feature-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Adventure ===== */
.adventure-header {
  margin-bottom: 16px;
}

.adventure-header h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.adv-progress {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.adv-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 3px;
  transition: width 0.4s ease;
}

.adventure-scene {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  min-height: 280px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.adventure-scene::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--accent));
}

.scene-text {
  margin-bottom: 16px;
  line-height: 1.7;
}

.scene-ayah {
  background: rgba(124,156,255,0.1);
  border-right: 4px solid var(--accent);
  padding: 14px 16px;
  margin: 16px 0;
  border-radius: 0 12px 12px 0;
  font-style: italic;
}

.scene-ayah .arabic {
  font-size: 1.3rem;
  direction: rtl;
  text-align: right;
  display: block;
  margin-bottom: 8px;
  font-family: 'Amiri', 'Traditional Arabic', serif;
  line-height: 1.8;
}

.scene-science {
  background: rgba(74, 222, 128, 0.08);
  border-right: 4px solid var(--success);
  padding: 14px 16px;
  margin: 16px 0;
  border-radius: 0 12px 12px 0;
}

.scene-ref {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.adventure-controls {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* ===== Knowledge ===== */
.knowledge-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-btn {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.knowledge-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.knowledge-card h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
  color: var(--gold);
}

.knowledge-card .arabic {
  direction: rtl;
  text-align: right;
  font-size: 1.25rem;
  margin: 10px 0;
  line-height: 1.9;
}

.knowledge-card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(124,156,255,0.15);
  color: var(--accent);
}

.btn-play-ayah {
  margin-top: 10px;
  padding: 8px 16px;
  font-size: 0.9rem;
}

/* ===== Quiz ===== */
.quiz-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.quiz-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

#quiz-bar-fill {
  height: 100%;
  width: 10%;
  background: var(--accent);
  transition: width 0.3s;
}

.quiz-question {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 1px solid var(--border);
  font-size: 1.05rem;
}

.quiz-options {
  display: grid;
  gap: 10px;
}

.quiz-opt {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: right;
  transition: border-color 0.2s, background 0.2s;
}

.quiz-opt:hover {
  border-color: var(--accent);
}

.quiz-opt.correct {
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.15);
}

.quiz-opt.wrong {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.12);
}

.quiz-feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 6px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  margin: 24px auto;
  color: var(--accent);
}

/* ===== Audio ===== */
.audio-item, .hadith-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.audio-item h4, .hadith-item h4 {
  margin-bottom: 6px;
  color: var(--gold);
}

.audio-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  z-index: 300;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}

.ap-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

#main-audio {
  width: 100%;
  height: 36px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
}

.modal-content h2 {
  margin-bottom: 20px;
  color: var(--gold);
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.theme-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.theme-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* ===== Progress ===== */
.progress-cards {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.progress-card {
  background: var(--bg-card);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* ===== About ===== */
.about-content {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.about-content h3 {
  margin: 16px 0 8px;
  color: var(--gold);
}

.about-content ul {
  padding-right: 20px;
  margin-bottom: 12px;
}

.about-content li {
  margin-bottom: 6px;
  color: var(--text-muted);
}

.version {
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .feature-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .hero h2 {
    font-size: 1.8rem;
  }
}

@media (max-width: 400px) {
  .quick-stats {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .stat-num {
    font-size: 1.2rem;
  }
}
