/* ==========================================================================
   src/styles/base.css
   Design System Tokens, Color Palettes (Light, Dark, Sepia, High-Contrast),
   Global Motion System Variables, SVG Crisp Rendering, and Global Resets
   ========================================================================== */

:root, [data-theme="light"] {
  --bg-primary: #FAF9F6;
  --bg-secondary: #F2EFE9;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-hover: #EAE6DF;
  --bg-active: #E0DBD1;
  --text-primary: #18181B;
  --text-secondary: #52525B;
  --text-muted: #71717A;
  --border-color: #E4E2DD;
  --border-strong: #CBC7BE;
  --accent: #6B4F35;
  --accent-hover: #543D28;
  --accent-soft: #F3ECE4;
  --verse-num: #8C6D4F;
  --hl-yellow: rgba(234, 179, 8, 0.24);
  --hl-green: rgba(34, 197, 94, 0.22);
  --hl-blue: rgba(59, 130, 246, 0.20);
  --hl-rose: rgba(244, 63, 94, 0.20);
  --focus-ring: #6B4F35;
}

[data-theme="dark"] {
  --bg-primary: #121316;
  --bg-secondary: #1A1C20;
  --bg-surface: #181A1E;
  --bg-elevated: #22252A;
  --bg-hover: #262930;
  --bg-active: #2F333C;
  --text-primary: #E6E4E0;
  --text-secondary: #A1A1AA;
  --text-muted: #71717A;
  --border-color: #2A2D34;
  --border-strong: #3F434E;
  --accent: #C8A97E;
  --accent-hover: #D9BE98;
  --accent-soft: rgba(200, 169, 126, 0.14);
  --verse-num: #C8A97E;
  --hl-yellow: rgba(234, 179, 8, 0.28);
  --hl-green: rgba(34, 197, 94, 0.26);
  --hl-blue: rgba(59, 130, 246, 0.26);
  --hl-rose: rgba(244, 63, 94, 0.26);
  --focus-ring: #C8A97E;
}

[data-theme="sepia"] {
  --bg-primary: #F4ECD8;
  --bg-secondary: #EAE0C8;
  --bg-surface: #F9F4E8;
  --bg-elevated: #FDF9F0;
  --bg-hover: #E4D8BE;
  --bg-active: #D8C9AA;
  --text-primary: #3B2B1D;
  --text-secondary: #5C4632;
  --text-muted: #846A52;
  --border-color: #DCD0B8;
  --border-strong: #C4B497;
  --accent: #7C4D25;
  --accent-hover: #613B1B;
  --accent-soft: #E8DCC4;
  --verse-num: #8C5828;
  --hl-yellow: rgba(217, 155, 26, 0.28);
  --hl-green: rgba(46, 150, 78, 0.24);
  --hl-blue: rgba(54, 115, 189, 0.22);
  --hl-rose: rgba(204, 71, 94, 0.22);
  --focus-ring: #7C4D25;
}

[data-contrast="high"][data-theme="light"] {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F0F0F0;
  --bg-surface: #FFFFFF;
  --text-primary: #000000;
  --text-secondary: #1F1F1F;
  --border-color: #888888;
  --accent: #3D2713;
}

[data-contrast="high"][data-theme="dark"] {
  --bg-primary: #000000;
  --bg-secondary: #111111;
  --bg-surface: #0A0A0A;
  --text-primary: #FFFFFF;
  --text-secondary: #E0E0E0;
  --border-color: #666666;
  --accent: #F0D098;
}

:root {
  --ui-font: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
  --reading-font: 'Amiri', Georgia, serif;
  --reading-size: 24px;
  --reading-line-height: 2.05;
  --reading-para-gap: 14px;
  --reading-max-width: 740px;

  /* Global Motion System Tokens (Durations & Easing Curves) */
  --motion-micro: 150ms;
  --motion-normal: 230ms;
  --motion-page: 260ms;
  --motion-modal: 280ms;
  --motion-drawer: 260ms;
  --ease-standard: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out-soft: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Central Motion Reduction via App Toggle OR OS System Preference */
[data-reduce-motion="true"] {
  --motion-micro: 0ms !important;
  --motion-normal: 0ms !important;
  --motion-page: 0ms !important;
  --motion-modal: 0ms !important;
  --motion-drawer: 0ms !important;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-micro: 0ms !important;
    --motion-normal: 0ms !important;
    --motion-page: 0ms !important;
    --motion-modal: 0ms !important;
    --motion-drawer: 0ms !important;
  }
}

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

html {
  margin: 0;
  padding: 0;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--ui-font);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  padding-top: 4rem; /* Compensate for fixed 4rem (64px) top header */
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--ui-font);
  direction: rtl;
  text-align: right;
  overflow-x: clip;
  min-height: 100vh;
  transition: background-color var(--motion-normal) var(--ease-in-out-soft),
              color var(--motion-normal) var(--ease-in-out-soft);
}

[data-reduce-motion="true"] *,
[data-reduce-motion="true"] *::before,
[data-reduce-motion="true"] *::after {
  transition-duration: 0.001ms !important;
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Task 2: Crisp SVG Icon Rendering System across Desktop & Mobile Sizes
   ========================================================================== */
svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  overflow: visible;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
  transition: transform var(--motion-micro) var(--ease-standard),
              color var(--motion-micro) var(--ease-standard),
              opacity var(--motion-micro) var(--ease-standard);
}

svg path,
svg circle,
svg rect,
svg line,
svg polyline,
svg polygon {
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Standardized Reference Icon Size System */
.icon-xs { width: 0.875rem; height: 0.875rem; } /* 14px */
.icon-sm { width: 1rem; height: 1rem; }         /* 16px */
.icon-md { width: 1.125rem; height: 1.125rem; } /* 18px */
.icon-lg { width: 1.25rem; height: 1.25rem; }   /* 20px */
.icon-xl { width: 1.5rem; height: 1.5rem; }     /* 24px */

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

/* Accessible Focus Ring */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Offline fallback for essential utility classes when Tailwind CDN is unreachable */
.hidden {
  display: none !important;
}
@media (min-width: 768px) {
  .md\:flex { display: flex !important; }
  .md\:inline-flex { display: inline-flex !important; }
  .md\:hidden { display: none !important; }
}
@media (min-width: 1024px) {
  .lg\:hidden { display: none !important; }
}
svg.w-3\.5 { width: 0.875rem; height: 0.875rem; }
svg.w-4 { width: 1rem; height: 1rem; }
svg.w-5 { width: 1.25rem; height: 1.25rem; }

/* ==========================================================================
   Comprehensive Offline Utility Fallback Layer (when Tailwind CDN is offline)
   Ensures all layout, spacing, typography, grid, flex, and responsive classes
   render the exact visual identity even without internet connectivity.
   ========================================================================== */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.block { display: block; }
.inline-block { display: inline-block; }
.grid { display: grid; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; }
.shrink-0 { flex-shrink: 0; }
.min-w-0 { min-width: 0px; }
.min-h-screen { min-height: 100vh; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }

.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.top-0 { top: 0; }
.top-2 { top: 0.5rem; }
.top-3\.5 { top: 0.875rem; }
.top-4 { top: 1rem; }
.top-16 { top: 4rem; }
.top-\[4\.25rem\] { top: 4.25rem; }
.bottom-0 { bottom: 0; }
.bottom-16 { bottom: 4rem; }
.bottom-20 { bottom: 5rem; }
.right-0 { right: 0; }
.right-2\.5 { right: 0.625rem; }
.right-3 { right: 0.75rem; }
.right-1\/2 { right: 50%; }
.left-0 { left: 0; }
.left-3 { left: 0.75rem; }
.left-4 { left: 1rem; }
.left-6 { left: 1.5rem; }
.z-20 { z-index: 20; }
.z-30 { z-index: 30; }
.z-40 { z-index: 40; }
.z-50 { z-index: 50; }

.w-full { width: 100%; }
.w-80 { width: 20rem; }
.w-12 { width: 3rem; }
.w-10 { width: 2.5rem; }
.w-9 { width: 2.25rem; }
.w-5 { width: 1.25rem; }
.w-4 { width: 1rem; }
.w-3\.5 { width: 0.875rem; }
.w-2\.5 { width: 0.625rem; }
.w-2 { width: 0.5rem; }
.w-\[94\%\] { width: 94%; }
.w-\[calc\(100vw-1\.5rem\)\] { width: calc(100vw - 1.5rem); }

.h-16 { height: 4rem; }
.h-12 { height: 3rem; }
.h-9 { height: 2.25rem; }
.h-5 { height: 1.25rem; }
.h-4 { height: 1rem; }
.h-3\.5 { height: 0.875rem; }
.h-2\.5 { height: 0.625rem; }
.h-2 { height: 0.5rem; }
.h-\[calc\(100vh-4rem\)\] { height: calc(100vh - 4rem); }
.max-h-\[90vh\] { max-height: 90vh; }

.max-w-xs { max-width: 20rem; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.max-w-xl { max-width: 36rem; }
.max-w-3xl { max-width: 48rem; }
.max-w-4xl { max-width: 56rem; }
.max-w-5xl { max-width: 64rem; }
.max-w-\[140px\] { max-width: 140px; }
.max-w-\[220px\] { max-width: 220px; }

.mx-auto { margin-left: auto; margin-right: auto; }
.my-4 { margin-top: 1rem; margin-bottom: 1rem; }
.mr-1 { margin-right: 0.25rem; }
.mt-0\.5 { margin-top: 0.125rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-4 { margin-top: 1rem; }
.mt-12 { margin-top: 3rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-1\.5 { margin-bottom: 0.375rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-2\.5 { margin-bottom: 0.625rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-8 { margin-bottom: 2rem; }

.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-2\.5 { padding: 0.625rem; }
.p-3 { padding: 0.75rem; }
.p-3\.5 { padding: 0.875rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.px-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-1\.5 { padding-left: 0.375rem; padding-right: 0.375rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-2\.5 { padding-left: 0.625rem; padding-right: 0.625rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-3\.5 { padding-left: 0.875rem; padding-right: 0.875rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-0\.5 { padding-top: 0.125rem; padding-bottom: 0.125rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-1\.5 { padding-top: 0.375rem; padding-bottom: 0.375rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-2\.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-6 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.pt-0\.5 { padding-top: 0.125rem; }
.pt-1 { padding-top: 0.25rem; }
.pt-2 { padding-top: 0.5rem; }
.pt-3 { padding-top: 0.75rem; }
.pt-4 { padding-top: 1rem; }
.pt-6 { padding-top: 1.5rem; }
.pb-1 { padding-bottom: 0.25rem; }
.pb-2 { padding-bottom: 0.5rem; }
.pb-3 { padding-bottom: 0.75rem; }
.pb-4 { padding-bottom: 1rem; }
.pb-8 { padding-bottom: 2rem; }
.pb-20 { padding-bottom: 5rem; }
.pl-3 { padding-left: 0.75rem; }
.pl-4 { padding-left: 1rem; }
.pr-8 { padding-right: 2rem; }
.pr-10 { padding-right: 2.5rem; }

.gap-1 { gap: 0.25rem; }
.gap-1\.5 { gap: 0.375rem; }
.gap-2 { gap: 0.5rem; }
.gap-2\.5 { gap: 0.625rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-5 { gap: 1.25rem; }

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.space-y-1 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.25rem; }
.space-y-2 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.5rem; }
.space-y-2\.5 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.625rem; }
.space-y-3 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.75rem; }
.space-y-3\.5 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.875rem; }
.space-y-4 > :not([hidden]) ~ :not([hidden]) { margin-top: 1rem; }
.space-y-6 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.5rem; }

.rounded { border-radius: 0.25rem; }
.rounded-md { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-xl { border-radius: 0.75rem; }
.rounded-2xl { border-radius: 1rem; }
.rounded-full { border-radius: 9999px; }

.border { border-width: 1px; border-style: solid; }
.border-t { border-top-width: 1px; border-top-style: solid; }
.border-b { border-bottom-width: 1px; border-bottom-style: solid; }
.border-l { border-left-width: 1px; border-left-style: solid; }

.text-\[10px\] { font-size: 10px; }
.text-\[11px\] { font-size: 11px; }
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.leading-tight { line-height: 1.25; }
.leading-relaxed { line-height: 1.625; }
.tracking-tight { letter-spacing: -0.025em; }
.tracking-wider { letter-spacing: 0.05em; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.uppercase { text-transform: uppercase; }
.align-middle { vertical-align: middle; }
.select-text { user-select: text; }
.cursor-pointer { cursor: pointer; }
.pointer-events-none { pointer-events: none; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.translate-x-1\/2 { transform: translateX(50%); }
.translate-x-full { transform: translateX(100%); }
.shadow-sm { box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1); }
.shadow-xl { box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1); }
.opacity-60 { opacity: 0.6; }
.opacity-75 { opacity: 0.75; }
.opacity-80 { opacity: 0.8; }
.text-rose-600 { color: #e11d48; }
.bg-white { background-color: #ffffff; }
.bg-zinc-800 { background-color: #27272a; }
.bg-zinc-900 { background-color: #18181b; }
.bg-\[\#E8DCC4\] { background-color: #E8DCC4; }
.bg-black\/40 { background-color: rgba(0, 0, 0, 0.4); }
.bg-black\/50 { background-color: rgba(0, 0, 0, 0.5); }
.accent-\[var\(--accent\)\] { accent-color: var(--accent); }

@media (min-width: 640px) {
  .sm\:flex-row { flex-direction: row; }
  .sm\:items-center { align-items: center; }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
  .sm\:px-8 { padding-left: 2rem; padding-right: 2rem; }
  .sm\:py-8 { padding-top: 2rem; padding-bottom: 2rem; }
  .sm\:py-12 { padding-top: 3rem; padding-bottom: 3rem; }
  .sm\:p-5 { padding: 1.25rem; }
  .sm\:p-8 { padding: 2rem; }
  .sm\:text-3xl { font-size: 1.875rem; line-height: 2.25rem; }
  .sm\:text-4xl { font-size: 2.25rem; line-height: 2.5rem; }
  .sm\:w-80 { width: 20rem; }
  .sm\:left-6 { left: 1.5rem; }
  .sm\:max-w-\[155px\] { max-width: 155px; }
  .sm\:max-w-\[240px\] { max-width: 240px; }
}

@media (min-width: 768px) {
  .md\:bottom-6 { bottom: 1.5rem; }
  .md\:pb-12 { padding-bottom: 3rem; }
}

@media (min-width: 1024px) {
  .lg\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
  .lg\:translate-x-0 { transform: translateX(0); }
  .lg\:grid-cols-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .lg\:col-span-5 { grid-column: span 5 / span 5; }
  .lg\:col-span-7 { grid-column: span 7 / span 7; }
}
