/* Shia Academy Web App — light & dark themes */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root,
[data-theme="light"] {
  color-scheme: light;
  --primary: #3399E6;
  --primary-rgb: 51, 153, 230;
  --text: #263955;
  --text-muted: #718096;
  --bg: #f2f7fc;
  --card: #fff;
  --border: #e2e8f0;
  --input-bg: #fff;
  --input-text: #263955;
  --menu-hover: #f7fafc;
  --intro-bg: #fff;
  --overlay: rgba(0, 0, 0, 0.4);
  --danger: #e53e3e;
  --success: #38a169;
  --radius: 20px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --stars-bg: #fef3c7;
  --stars-text: #92400e;
  --error-banner-bg: #fed7d7;
  --error-banner-text: #c53030;
  --match-btn-bg: #fff;
  --match-matched-bg: #f0fff4;
  --auth-gradient-start: #20b2aa;
  --auth-gradient-end: #ffd85f;
  --theme-toggle-bg: rgba(255, 255, 255, 0.25);
  --theme-toggle-border: rgba(255, 255, 255, 0.45);
}

[data-theme="dark"] {
  color-scheme: dark;
  --primary: #5eb3f0;
  --primary-rgb: 94, 179, 240;
  --text: #e8eef5;
  --text-muted: #94a3b8;
  --bg: #0f172a;
  --card: #1e293b;
  --border: #334155;
  --input-bg: #0f172a;
  --input-text: #e8eef5;
  --menu-hover: #334155;
  --intro-bg: #0f172a;
  --overlay: rgba(0, 0, 0, 0.65);
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --stars-bg: rgba(251, 191, 36, 0.18);
  --stars-text: #fcd34d;
  --error-banner-bg: rgba(229, 62, 62, 0.22);
  --error-banner-text: #fca5a5;
  --match-btn-bg: #1e293b;
  --match-matched-bg: rgba(56, 161, 105, 0.18);
  --auth-gradient-start: #0d4f4a;
  --auth-gradient-end: #5c4a1f;
  --theme-toggle-bg: rgba(255, 255, 255, 0.1);
  --theme-toggle-border: rgba(255, 255, 255, 0.2);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; }

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--theme-toggle-border);
  background: var(--theme-toggle-bg);
  backdrop-filter: blur(8px);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.2s ease;
}
.theme-toggle:hover { transform: scale(1.05); }
.theme-toggle--header {
  position: static;
  width: 40px;
  height: 40px;
  font-size: 18px;
  border-color: var(--border);
  background: rgba(var(--primary-rgb), 0.1);
  flex-shrink: 0;
}

/* Offline */
.offline-banner {
  background: #d97706;
  color: #fff;
  padding: 12px 16px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Intro */
.intro-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--intro-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  animation: fadeIn 0.6s ease;
}
.intro-logo { font-size: 64px; }
.app-logo {
  display: block;
  object-fit: contain;
  margin-left: auto;
  margin-right: auto;
}
.app-logo--intro { width: 160px; height: 160px; }
.app-logo--auth { width: 88px; height: 88px; margin-bottom: 16px; }
.app-logo--hero { width: 96px; height: 96px; margin-bottom: 12px; }
.intro-screen p { font-size: 28px; font-weight: 700; color: var(--text); }

/* Auth */
.auth-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--auth-gradient-start), var(--auth-gradient-end));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 28px; margin-bottom: 4px; color: var(--text); }
.auth-card:has(.app-logo--auth) h1,
.auth-card:has(.app-logo--auth) .subtitle { text-align: center; }
.subtitle { color: var(--text-muted); margin-bottom: 20px; }
.auth-card input,
.profile-form input,
.auth-gate input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--input-bg);
  color: var(--input-text);
}
.profile-form input { margin-top: 4px; margin-bottom: 0; }
.auth-gate input { margin: 12px 0; }
.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-secondary { background: rgba(var(--primary-rgb), 0.12); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); padding: 8px 12px; }
.btn-small { padding: 8px 12px; font-size: 14px; }
.btn-done { background: var(--success); color: #fff; width: 100%; margin-top: 16px; }
.btn-done.completed { opacity: 0.9; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; margin-top: 12px; width: 100%; font-size: 15px; }
.btn.danger, .danger { color: var(--danger); }
.error { color: var(--danger); font-size: 14px; margin-bottom: 8px; }
.success { color: var(--success); font-size: 14px; }

/* App shell */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header h2 { font-size: 18px; font-weight: 700; flex: 1; text-align: center; color: var(--text); }
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.back-btn, .menu-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--primary);
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
}
.menu-wrap { position: relative; }
.menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 200px;
  overflow: hidden;
  z-index: 200;
}
.menu-dropdown button, .menu-dropdown a {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.menu-dropdown button:hover, .menu-dropdown a:hover { background: var(--menu-hover); }

.main-content { max-width: 720px; margin: 0 auto; padding-bottom: 40px; }
.page { padding: 16px 20px 40px; min-height: calc(100vh - 60px); }

/* Home */
.hero { text-align: center; padding: 20px 0 16px; }
.hero-icon { font-size: 48px; margin-bottom: 8px; }
.hero .app-logo--hero { margin-left: auto; margin-right: auto; }
.hero h1 { font-size: 32px; color: var(--text); }
.tagline { color: var(--text-muted); font-size: 16px; margin-top: 8px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  color: var(--text);
}
.info-card h3 { margin-bottom: 8px; color: var(--text); }
.sync-card { background: rgba(var(--primary-rgb), 0.08); border: 1px solid rgba(var(--primary-rgb), 0.2); }
.learner-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 18px;
  color: var(--text);
}
.learner-banner .emoji { font-size: 28px; }
.learner-banner .stars {
  background: var(--stars-bg);
  color: var(--stars-text);
  padding: 6px 12px;
  border-radius: 12px;
  font-weight: 700;
}

.category-list { display: flex; flex-direction: column; gap: 16px; }
.category-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
  color: var(--text);
}
.category-card:not(.locked):hover { transform: scale(0.98); }
.category-card.locked { opacity: 0.7; cursor: default; }
.cat-icon {
  width: 70px; height: 70px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.cat-icon.large { width: 100px; height: 100px; font-size: 48px; margin: 0 auto 12px; }
.cat-text h3 { font-size: 22px; color: var(--text); }
.cat-text .arabic { font-size: 18px; margin: 2px 0; }
.muted { color: var(--text-muted); font-size: 14px; }
.center { text-align: center; }
.cat-arrow { font-size: 28px; opacity: 0.6; }

/* Category detail */
.category-hero { text-align: center; padding: 16px 0 24px; }
.category-hero h1 { color: var(--text); }
.section-title { font-size: 20px; margin-bottom: 12px; color: var(--text); }
.activity-list { display: flex; flex-direction: column; gap: 12px; }
.activity-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  cursor: pointer;
  color: var(--text);
}
.activity-row.locked { opacity: 0.7; cursor: default; }
.act-icon {
  width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; flex-shrink: 0;
}
.activity-row h4 { font-size: 18px; color: var(--text); }

/* Activity */
.activity-header-wrap { text-align: center; padding: 16px 0; }
.activity-header h1 { font-size: 24px; margin: 12px 0 4px; color: var(--text); }
.type-badge {
  display: inline-block; margin-top: 8px;
  background: rgba(var(--primary-rgb), 0.12);
  color: var(--primary); padding: 4px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
}
.activity-type-icon {
  width: 80px; height: 80px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; margin: 0 auto;
}
.activity-card { margin-top: 8px; }
.activity-image { width: 100%; max-height: 280px; object-fit: contain; border-radius: 12px; }
.activity-image.large { max-height: 320px; }
.image-placeholder {
  height: 120px; display: flex; align-items: center; justify-content: center;
  background: rgba(var(--primary-rgb), 0.1); border-radius: 12px; font-size: 48px;
}
.image-placeholder.large { height: 200px; font-size: 64px; }
.activity-text { font-size: 16px; margin-top: 16px; line-height: 1.6; color: var(--text); }
.activity-text.center { text-align: center; }
.hint { color: var(--text-muted); font-size: 15px; margin-bottom: 12px; }
.hint.bold { font-weight: 700; color: var(--text); }
.success-msg { color: var(--success); font-weight: 700; text-align: center; margin-top: 16px; font-size: 18px; }

.audio-wrap { margin: 16px 0; }
.audio-progress { width: 100%; margin-bottom: 8px; accent-color: var(--primary); }
.audio-time { font-size: 13px; color: var(--text-muted); }
.audio-controls { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

.action-row { display: flex; gap: 12px; margin-top: 16px; }
.action-row .btn { flex: 1; }

.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-btn {
  width: 100%; padding: 12px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--match-btn-bg);
  color: var(--text); cursor: pointer;
  font-size: 15px; margin-bottom: 8px;
}
.match-btn.selected { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.1); }
.match-btn.matched { border-color: var(--success); background: var(--match-matched-bg); opacity: 0.7; }

.puzzle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; aspect-ratio: 1; max-width: 360px; margin: 0 auto; }
.puzzle-cell {
  border: none; border-radius: 8px; aspect-ratio: 1;
  background-color: rgba(var(--primary-rgb), 0.2);
  background-repeat: no-repeat; cursor: pointer; font-size: 24px; font-weight: 700;
  color: var(--text);
}
.puzzle-cell.selected { outline: 3px solid #fbbf24; }

.memory-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.memory-card {
  height: 80px; border-radius: 16px; border: none;
  background: rgba(var(--primary-rgb), 0.35); color: #fff;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.memory-card.flipped { background: rgba(var(--primary-rgb), 0.15); color: var(--primary); }

.certificate-reveal {
  width: 100%; min-height: 220px; border: none; border-radius: 24px;
  background: rgba(var(--primary-rgb), 0.2); font-size: 64px; cursor: pointer;
}
.certificate-reveal.revealed { background: transparent; cursor: default; min-height: auto; }

/* About */
.about-page { text-align: center; max-width: 520px; margin: 24px auto; color: var(--text); }
.about-page h1 { color: var(--text); }
.about-page .app-logo--hero { margin-bottom: 12px; }
.link-list { display: flex; flex-direction: column; gap: 12px; margin: 24px 0; }
.link-list a,
.link-list button {
  display: block; padding: 14px; border-radius: 14px;
  background: rgba(var(--primary-rgb), 0.08); color: var(--primary);
  text-decoration: none; font-weight: 600;
  width: 100%; text-align: left; font-family: inherit; font-size: 16px;
  border: none; cursor: pointer;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 16px;
}
.modal {
  background: var(--bg); border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto;
  padding: 20px;
  color: var(--text);
}
.profiles-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.profiles-header h2 { color: var(--text); }
.btn-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.profile-list { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.profile-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); padding: 16px; border-radius: 16px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  color: var(--text);
}
.profile-card.selected { border-color: var(--success); }
.profile-card .emoji { font-size: 32px; }
.profile-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.selected-badge { color: var(--success); font-weight: 600; font-size: 13px; }
.emoji-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.emoji-btn {
  font-size: 28px; padding: 8px; border: none; border-radius: 10px;
  background: transparent; cursor: pointer;
}
.emoji-btn.active { background: rgba(var(--primary-rgb), 0.2); }
.profile-form label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--text); }
.form-actions { display: flex; gap: 12px; margin-top: 16px; }
.form-actions .btn { flex: 1; }

.loading { text-align: center; padding: 24px; color: var(--text-muted); }
.error-banner {
  background: var(--error-banner-bg);
  color: var(--error-banner-text);
  padding: 12px; border-radius: 12px; margin-bottom: 16px; text-align: center;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Cookie consent */
.cookie-consent {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 1100;
  padding: 16px;
  animation: fadeIn 0.3s ease;
}
.cookie-consent-inner {
  max-width: 720px;
  margin: 0 auto;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.cookie-consent-inner h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text);
}
.cookie-consent-inner p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.cookie-consent-inner a {
  color: var(--primary);
  font-weight: 600;
}
.cookie-consent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.cookie-consent-actions .btn {
  flex: 1;
  min-width: 140px;
}

@media (min-width: 768px) {
  .main-content { padding-top: 8px; }
}
