/* ==========================================================================
   Core Design System & Shared Styles (common.css) - QOMAR Project
   ========================================================================== */

:root {
  /* ===== Color Palette: Extracted from QOMAR Logo ===== */
  --color-cream-50: #FFFDF2;
  --color-cream-100: #FFF9D4;
  --color-cream-200: #FFEAA2;
  --color-cream-300: #FAD15B;
  --color-cream-400: #E6B525;

  --color-blue-50: #F0F4FF;
  --color-blue-100: #E5EEFF;
  --color-blue-200: #C1D5FE;
  --color-blue-300: #8EB3FD;
  --color-blue-400: #00A8E8;
  --color-blue-500: #1967de;
  --color-blue-600: #2457b3;
  --color-blue-700: #1a4da6;
  --color-blue-800: #022680;
  /* Logo Deep Blue */
  --color-blue-900: #011E62;
  /* Very Dark Blue for text */

  /* Logo accents */
  --color-pink-500: #E2528C;
  /* Hijab Pink */
  --color-teal-500: #139C80;
  /* Shirt Teal */
  --color-purple-500: #7A22A8;
  /* Ornate Purple */
  --color-gold-400: #FFCF27;
  /* Title Yellow */

  --color-green-400: #4CAF50;
  --color-green-500: #388E3C;
  --color-red-400: #EF5350;
  --color-red-500: #D32F2F;

  /* ===== Fonts ===== */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-arabic: 'Amiri', "Traditional Arabic", serif;
  --font-dyslexia: "OpenDyslexic", "Comic Sans MS", sans-serif;

  /* ===== Shadows & Spacing ===== */
  --shadow-soft: 0 2px 15px rgba(2, 38, 128, 0.08);
  --shadow-card: 0 4px 24px rgba(2, 38, 128, 0.12);
  --shadow-elevated: 0 8px 40px rgba(2, 38, 128, 0.16);
  --shadow-glow: 0 0 20px rgba(255, 207, 39, 0.4);

  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;
  --radius-3xl: 1.5rem;

  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* @font-face for OpenDyslexic (copied to Public/fonts/) */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../Public/fonts/OpenDyslexic-Regular.woff2') format('woff2'),
    url('../Public/fonts/OpenDyslexic-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

/* ===== Global UDL Scalability Engine ===== */
html {
  scroll-behavior: smooth;
}

/* ===== Global UDL Scalability Engine ===== */
html.font-scale-100 { --udl-scale: 1; --udl-img-scale: 1; }
html.font-scale-110 { --udl-scale: 1.1; --udl-img-scale: 1.08; }
html.font-scale-120 { --udl-scale: 1.2; --udl-img-scale: 1.16; }
html.font-scale-130 { --udl-scale: 1.3; --udl-img-scale: 1.24; }
html.font-scale-140 { --udl-scale: 1.4; --udl-img-scale: 1.32; }
html.font-scale-150 { --udl-scale: 1.5; --udl-img-scale: 1.40; }
html.font-scale-160 { --udl-scale: 1.6; --udl-img-scale: 1.48; }

/* Apply Fluid Zoom Scaling ONLY to Main Content Areas (Excluding Header Navbar & Bottom Footer Navigation) */
.landing-container,
.vocab-container,
.vocab-grid-wrapper,
.comic-viewer-card,
.video-container,
.quiz-main-content {
  font-size: calc(1rem * var(--udl-scale, 1));
  padding-top: calc(0.5rem * var(--udl-scale, 1));
  transition: font-size 0.25s cubic-bezier(0.4, 0, 0.2, 1), padding 0.25s ease;
}

/* ===== Base Styles ===== */
[lang="ar"], .arabic-text {
  font-family: var(--font-arabic);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: linear-gradient(135deg, var(--color-cream-50) 0%, var(--color-cream-100) 50%, var(--color-blue-50) 100%);
  color: var(--color-blue-900);
  min-height: 100vh;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* Base class for decorative pattern in background */
.bg-pattern {
  background-image:
    radial-gradient(circle at 20% 80%, rgba(18, 86, 224, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 207, 39, 0.06) 0%, transparent 50%);
  background-attachment: fixed;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ===== Glassmorphism Cards ===== */
.glass-card {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2.5px solid rgba(2, 38, 128, 0.15);
  box-shadow: var(--shadow-card);
  transform: translateZ(0);
}

.glass-card-strong {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 2.5px solid rgba(2, 38, 128, 0.25);
  box-shadow: var(--shadow-elevated);
  transform: translateZ(0);
}

/* ===== Dyslexia Mode Overrides ===== */
body.dyslexia-mode {
  font-family: var(--font-dyslexia) !important;
  letter-spacing: 0.05em;
  word-spacing: 0.12em;
}

body.dyslexia-mode * {
  font-family: inherit !important;
  line-height: 1.8 !important;
}

body.dyslexia-mode [lang="ar"],
body.dyslexia-mode .arabic-text {
  font-family: var(--font-arabic) !important;
}

/* ===== CSS Keyframes Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

@keyframes pulse-soft {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.65;
  }
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulseGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(2, 38, 128, 0.3);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(2, 38, 128, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(2, 38, 128, 0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popoverShow {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Animation classes */
.animate-fade-in {
  animation: fadeIn 0.4s ease-out both;
}

.animate-slide-right {
  animation: slideInRight 0.4s ease-out both;
}

.animate-slide-left {
  animation: slideInLeft 0.4s ease-out both;
}

.animate-float {
  animation: float 2.5s ease-in-out infinite;
}

.animate-pulse-soft {
  animation: pulse-soft 2s ease-in-out infinite;
}

.animate-fade-in-up {
  animation: fade-in-up 0.5s ease-out both;
}

.animate-pulse-glow {
  animation: pulseGlow 2s infinite;
}

/* ===== Shared Navigation Elements ===== */
.back-link {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--color-blue-500);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  transition: color 0.2s, transform 0.2s;
}

.back-link:hover {
  color: var(--color-blue-700);
  transform: translateX(-2px);
}

.chevron-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

/* ===== Main Header & UDL Toolbar (Mobile First) ===== */
.main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  padding: 0.5rem 0;
  border-top: none;
  border-left: none;
  border-right: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  margin-bottom: 1.25rem;
}

.header-container {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
}

.header-left {
  order: 1;
  flex: 1 1 auto;
  justify-content: flex-start;
}

.header-center {
  order: 3;
  flex: 1 0 100%; /* forces center title to wrap to a new line on small mobile */
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0.25rem;
}

.header-title {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--color-blue-800);
  letter-spacing: 0.5px;
}

.header-right {
  order: 2;
  flex: 0 0 auto;
  justify-content: flex-end;
}

/* UDL Toolbar */
.udl-toolbar {
  display: flex;
  align-items: center;
  background: rgba(2, 38, 128, 0.05);
  border: 1px solid rgba(2, 38, 128, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 50px;
  gap: 0.35rem;
}

.udl-btn {
  background: transparent;
  border: none;
  color: var(--color-blue-800);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
}

.udl-btn:hover {
  background: rgba(2, 38, 128, 0.08);
  color: var(--color-blue-600);
  transform: scale(1.05);
}

.udl-btn:active {
  transform: scale(0.95);
}

.zoom-indicator {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-blue-900);
  min-width: 2.2rem;
  text-align: center;
}

.udl-divider {
  width: 1px;
  height: 1rem;
  background: rgba(2, 38, 128, 0.15);
}

.udl-btn.dyslexia-toggle {
  width: auto;
  padding: 0 0.5rem;
  border-radius: 50px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.udl-btn.dyslexia-toggle.active {
  background: var(--color-pink-500);
  color: white;
}

/* Desktop Enhancements (641px and up) */
@media (min-width: 641px) {
  .main-header {
    padding: 0.75rem 0;
    margin-bottom: 2rem;
  }

  .header-container {
    flex-flow: row nowrap;
    gap: 1rem;
    padding: 0;
  }

  .header-left {
    flex: 1;
  }

  .header-center {
    order: 2;
    flex: 1;
    margin-top: 0;
  }

  .header-title {
    font-size: 1.25rem;
  }

  .header-right {
    flex: 1;
  }

  .udl-toolbar {
    padding: 0.25rem 0.5rem;
    gap: 0.5rem;
  }

  .udl-btn {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.875rem;
  }

  .zoom-indicator {
    font-size: 0.8rem;
    min-width: 2.5rem;
  }

  .udl-divider {
    height: 1.25rem;
  }

  .udl-btn.dyslexia-toggle {
    padding: 0 0.75rem;
    font-size: 0.75rem;
  }
}

/* ==========================================================================
   PWA UI Elements (Install Banner & Notification Toasts)
   ========================================================================== */
.pwa-install-banner {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: calc(100% - 2rem);
  max-width: 480px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid #00A8E8;
  border-radius: 20px;
  box-shadow: 0 14px 40px rgba(0, 52, 102, 0.16);
  z-index: 9999;
  padding: 0.85rem 1rem;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  animation: pwaSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pwaSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.pwa-install-banner.pwa-hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(30px);
  pointer-events: none;
}

.pwa-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.pwa-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(0, 52, 102, 0.12);
}

.pwa-banner-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pwa-banner-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #003466;
  line-height: 1.2;
}

.pwa-banner-desc {
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.3;
  margin-top: 0.15rem;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pwa-btn-primary {
  min-height: 44px;
  padding: 0 1rem;
  background: #00A8E8;
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.pwa-btn-primary:hover,
.pwa-btn-primary:focus-visible {
  background: #008ec5;
  transform: scale(1.02);
}

.pwa-btn-text {
  min-height: 44px;
  padding: 0 0.65rem;
  background: transparent;
  color: #64748b;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.pwa-btn-text:hover,
.pwa-btn-text:focus-visible {
  color: #003466;
  background: rgba(0, 52, 102, 0.05);
}

/* Toasts */
.pwa-toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 10000;
  max-width: calc(100vw - 2.5rem);
  pointer-events: none;
}

.pwa-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  animation: pwaToastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s, transform 0.3s;
}

@keyframes pwaToastIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pwa-toast.pwa-toast-exit {
  opacity: 0;
  transform: translateY(16px);
}

.pwa-toast-info {
  background: #003466;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.pwa-toast-success,
.pwa-toast-online {
  background: #065f46;
  color: #ffffff;
}

.pwa-toast-offline {
  background: #991b1b;
  color: #ffffff;
}

.pwa-toast-update {
  background: #1e3a8a;
  color: #ffffff;
}

.pwa-toast-action {
  min-height: 36px;
  padding: 0 0.85rem;
  background: #00A8E8;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: auto;
}

.pwa-toast-action:hover,
.pwa-toast-action:focus-visible {
  background: #0090c7;
}

@media (max-width: 600px) {
  .pwa-install-banner {
    bottom: 0.85rem;
    padding: 0.75rem;
  }
  .pwa-toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }
}

/* ==========================================================================
   PWA Floating Install Button (FAB)
   ========================================================================== */
.pwa-fab {
  position: fixed;
  bottom: 1.5rem;
  left: 1.25rem;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 1.1rem;
  height: 48px;
  background: #00A8E8;
  color: #ffffff;
  border: none;
  border-radius: 50px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0, 168, 232, 0.42);
  /* Start invisible, slide in via .pwa-fab-visible */
  opacity: 0;
  transform: translateY(20px) scale(0.92);
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.2s ease,
              background-color 0.2s ease;
  /* Prevent text wrapping */
  white-space: nowrap;
}

.pwa-fab.pwa-fab-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.pwa-fab:hover,
.pwa-fab:focus-visible {
  background: #008ec5;
  box-shadow: 0 10px 30px rgba(0, 168, 232, 0.55);
  transform: translateY(-2px) scale(1.02);
  outline: none;
}

.pwa-fab:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 4px 14px rgba(0, 168, 232, 0.3);
}

.pwa-fab:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

.pwa-fab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-fab-label {
  letter-spacing: 0.01em;
}

/* Hide label on very small screens, show icon only */
@media (max-width: 360px) {
  .pwa-fab {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  .pwa-fab-label {
    display: none;
  }
}

/* Don't show FAB when banner is visible to avoid overlap */
.pwa-install-banner ~ * .pwa-fab,
body:has(.pwa-install-banner) .pwa-fab {
  display: none;
}

/* ─── Caching Progress Banner ─────────────────────────────────────────────── */
.pwa-caching-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: rgba(1, 30, 98, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  padding: 12px 20px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-top: 2px solid var(--color-gold-400);
}

.pwa-caching-banner.pwa-caching-visible {
  transform: translateY(0);
}

.pwa-caching-banner.pwa-caching-done {
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.4s ease, opacity 0.4s ease;
}

.pwa-caching-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pwa-caching-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  gap: 8px;
  flex-wrap: wrap;
}

.pwa-caching-text strong {
  color: var(--color-gold-400);
  font-weight: 700;
  font-size: 0.875rem;
}

.pwa-caching-text span {
  color: rgba(255, 255, 255, 0.72);
}

.pwa-caching-bar-wrap {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 99px;
  overflow: hidden;
}

.pwa-caching-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-blue-400), var(--color-gold-400));
  border-radius: 99px;
  transition: width 0.3s ease;
}
