/* ===== Variables & Themes ===== */
:root {
  --bg-primary: #0a1f1a;
  --bg-secondary: #0d2e24;
  --bg-card: #12352b;
  --text-primary: #e8f5e9;
  --text-secondary: #a5d6a7;
  --accent: #26a69a;
  --accent-hover: #2bbbad;
  --gold: #c9a227;
  --border: #1b5e4a;
  --shadow: rgba(0,0,0,0.4);
  --font-ar: 'Amiri', serif;
  --font-th: 'Sarabun', sans-serif;
  --radius: 12px;
  --transition: 0.25s ease;
}

body.theme-sepia {
  --bg-primary: #2c2416;
  --bg-secondary: #3d3220;
  --bg-card: #4a3f2a;
  --text-primary: #f5e6c8;
  --text-secondary: #d4b896;
  --accent: #c9a227;
  --accent-hover: #dbb53a;
  --border: #5c4d32;
}

body.theme-soft {
  --bg-primary: #1a2332;
  --bg-secondary: #243044;
  --bg-card: #2d3a52;
  --text-primary: #e0e6f0;
  --text-secondary: #a0b0c8;
  --accent: #5c7cfa;
  --accent-hover: #748ffc;
  --border: #3a4a66;
}

body.theme-light {
  --bg-primary: #f0f7f4;
  --bg-secondary: #e0efe8;
  --bg-card: #ffffff;
  --text-primary: #1a3c32;
  --text-secondary: #4a6b5e;
  --accent: #0d9488;
  --accent-hover: #14b8a6;
  --border: #b2d8cc;
  --shadow: rgba(0,0,0,0.1);
}

body.font-large { font-size: 18px; }
body.font-xlarge { font-size: 20px; }

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-th);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--accent); }

/* ===== Screens ===== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg-primary);
  z-index: 1;
}
.screen.active { display: flex; }

/* ===== Splash ===== */
#splash {
  justify-content: center;
  align-items: center;
  background: linear-gradient(160deg, #0a1f1a 0%, #0d3d30 50%, #0a1f1a 100%);
  text-align: center;
}
.splash-content { padding: 2rem; }
.bismillah {
  font-family: var(--font-ar);
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 1.5rem;
  direction: rtl;
}
.title-ar {
  font-family: var(--font-ar);
  font-size: 2.4rem;
  color: var(--gold);
  margin-bottom: 0.3rem;
  direction: rtl;
}
.title-th { font-size: 1.3rem; font-weight: 600; margin-bottom: 0.5rem; }
.subtitle { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 2rem; }
.loader {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-secondary); font-size: 0.85rem; }

/* ===== Menu ===== */
.menu-header {
  text-align: center;
  padding: 2rem 1.5rem 1rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
}
.bismillah-small {
  font-family: var(--font-ar);
  font-size: 1.1rem;
  color: var(--gold);
  direction: rtl;
  margin-bottom: 0.8rem;
}
.menu-header h1 {
  font-family: var(--font-ar);
  font-size: 1.8rem;
  color: var(--gold);
  direction: rtl;
}
.menu-header p { color: var(--text-secondary); margin-top: 0.3rem; }

.menu-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}
.btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 500;
  transition: var(--transition);
  text-align: left;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #1a7a6d);
  color: #fff;
  box-shadow: 0 4px 15px rgba(38,166,154,0.3);
}
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.btn-secondary:active { background: var(--bg-secondary); }
.btn-small {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.btn-icon { font-size: 1.3rem; }
.btn-icon-only {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 1.2rem;
}

.menu-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== Adventure ===== */
.adventure-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.progress-info { flex: 1; }
.progress-info span { font-size: 0.85rem; color: var(--text-secondary); }
.progress-bar {
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  margin-top: 4px;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

.adventure-body {
  flex: 1;
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.scene-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.25;
  pointer-events: none;
  transition: background-image 0.6s ease;
}
.scene-content {
  position: relative;
  padding: 1.25rem;
  max-width: 600px;
  margin: 0 auto;
}
.scene-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 1rem;
  text-align: center;
}
.scene-text {
  line-height: 1.7;
  margin-bottom: 1.5rem;
  white-space: pre-line;
}
.scene-choices {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.choice-btn {
  padding: 0.9rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  transition: var(--transition);
  font-size: 0.95rem;
}
.choice-btn:active, .choice-btn:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
}
.scene-knowledge {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  font-size: 0.9rem;
  line-height: 1.6;
}
.scene-knowledge.hidden { display: none; }
.scene-knowledge h4 {
  color: var(--gold);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.adventure-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ===== Knowledge & Settings & About ===== */
.sub-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.sub-header h2 { font-size: 1.15rem; }

.knowledge-list {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.knowledge-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: var(--transition);
}
.knowledge-card:active { border-color: var(--accent); }
.knowledge-card h3 { font-size: 1rem; color: var(--gold); margin-bottom: 0.3rem; }
.knowledge-card p { font-size: 0.85rem; color: var(--text-secondary); }

.settings-body, .about-body {
  padding: 1.25rem;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.setting-item label { flex: 1; }
.setting-item select, .setting-item input[type="checkbox"] {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
.setting-item input[type="checkbox"] {
  width: 22px; height: 22px;
  accent-color: var(--accent);
}
.about-body h3 { color: var(--gold); margin: 1.2rem 0 0.5rem; font-size: 1.05rem; }
.about-body ul { padding-left: 1.2rem; margin-bottom: 1rem; }
.about-body li { margin-bottom: 0.4rem; line-height: 1.5; font-size: 0.9rem; }
.about-body .note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.8rem;
  font-style: italic;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 0.75rem; right: 0.75rem;
  width: 36px; height: 36px;
  font-size: 1.5rem;
  border-radius: 50%;
  background: var(--bg-card);
}
#modal-body { padding-top: 0.5rem; }
#modal-body h3 { color: var(--gold); margin-bottom: 0.75rem; }
#modal-body .ar-text {
  font-family: var(--font-ar);
  font-size: 1.3rem;
  direction: rtl;
  line-height: 2;
  margin-bottom: 0.75rem;
  color: var(--gold);
}
#modal-body .th-text { line-height: 1.7; margin-bottom: 1rem; }
#modal-body .ref { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.5rem; }
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-content { border-radius: var(--radius); }
}
@media (min-width: 768px) {
  .menu-nav { max-width: 360px; }
  .scene-content { padding: 2rem; }
}

/* ===== Background patterns for stages ===== */
.bg-nutfah { background-image: radial-gradient(circle at 30% 40%, #1a5c4a 0%, transparent 50%), radial-gradient(circle at 70% 60%, #0d3d30 0%, transparent 40%); }
.bg-alaqah { background-image: radial-gradient(ellipse at 50% 50%, #4a1a1a 0%, transparent 60%); }
.bg-mudghah { background-image: radial-gradient(circle at 40% 50%, #3d2a1a 0%, transparent 50%); }
.bg-izam { background-image: linear-gradient(135deg, #1a2a3d 0%, #0d1a2a 100%); }
.bg-lahm { background-image: radial-gradient(circle at 50% 40%, #2a1a2a 0%, transparent 55%); }
.bg-khalq { background-image: radial-gradient(ellipse at 50% 30%, #1a3d4a 0%, transparent 60%); }
.bg-birth { background-image: linear-gradient(180deg, #1a3d2a 0%, #0a1f1a 100%); }
.bg-nursing { background-image: radial-gradient(circle at 50% 50%, #2a3d1a 0%, transparent 55%); }

/* ===== Stage Illustrations ===== */
.scene-image {
  text-align: center;
  padding: 0.75rem 1rem 0;
  max-width: 600px;
  margin: 0 auto;
}
.scene-image.hidden { display: none; }
.stage-illust {
  width: 100%;
  max-width: 320px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  border: 1px solid var(--border);
}

/* ===== Quiz ===== */
.quiz-box {
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-left: 3px solid var(--gold);
  margin-bottom: 0.75rem;
}
.quiz-q {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.5;
}
.quiz-opt {
  border-color: var(--accent) !important;
}
.quiz-result {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}
.quiz-result.correct {
  background: rgba(38, 166, 154, 0.2);
  border: 1px solid var(--accent);
}
.quiz-result.wrong {
  background: rgba(180, 60, 60, 0.2);
  border: 1px solid #c45c5c;
}
.quiz-result p:first-child {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

/* Improve adventure body spacing */
.scene-content {
  padding-top: 0.5rem;
}
