/* ==========================================================================
   BASE.CSS — Islamic PWA Redesign
   Requires tokens.css loaded first for all custom properties.
   All layout uses logical properties for automatic RTL support.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. MODERN CSS RESET
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
  scroll-behavior: smooth;
}

body,
h1, h2, h3, h4, h5, h6,
p,
blockquote,
figure,
fieldset,
legend,
dl, dd {
  margin: 0;
}

ul, ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-inline-size: 100%;
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}


/* --------------------------------------------------------------------------
   2. HTML & BODY — RTL, DARK, ARABIC OPTIMISED
   -------------------------------------------------------------------------- */

html {
  font-size: 112.5%; /* 18px base — better Arabic readability */
  direction: rtl;
}

body {
  min-block-size: 100dvh;
  background-color: var(--bg-deep);
  color: var(--fg-primary);
  font-family: var(--font-body);
  line-height: 1.9; /* generous for Arabic script */
  overflow-x: hidden;
  text-rendering: optimizeSpeed;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-overflow-scrolling: touch;
}


/* --------------------------------------------------------------------------
   2b. SECTION STICKY HEADERS — offset below unified bar (52px)
   All section-level sticky headers must clear the fixed unified top bar
   -------------------------------------------------------------------------- */

.athkar-header,
.athkar-progress-wrap,
.athkar-reader-top,
.duas-reader-top,
.tools-reader-top,
.reader-header {
  inset-block-start: 52px !important;
}

.reading-progress {
  inset-block-start: 52px;
}


/* --------------------------------------------------------------------------
   3. iOS STANDALONE — OVERSCROLL PREVENTION
   -------------------------------------------------------------------------- */

@media all and (display-mode: standalone) {
  html, body {
    overscroll-behavior-y: none;
  }

  body {
    min-height: 100%;
    min-height: -webkit-fill-available;
    padding-block-start: env(safe-area-inset-top, 0px);
  }

  /* Unified bar: sits at very top, accounts for safe area via its own padding */
  .unified-bar {
    inset-block-start: 0 !important;
  }

  /* Section sticky headers: sit below unified bar + safe area
     !important needed because section CSS sets inset-block-start: 0 */
  .athkar-header,
  .athkar-progress-wrap,
  .athkar-reader-top,
  .duas-reader-top,
  .tools-reader-top,
  .reader-header {
    inset-block-start: calc(52px + env(safe-area-inset-top, 0px)) !important;
  }

  /* Reading progress bar: push below unified bar + safe area */
  .reading-progress {
    inset-block-start: calc(52px + env(safe-area-inset-top, 0px));
  }

  /* Athkar header already has safe-area in its padding — remove to avoid double */
  .athkar-header {
    padding-block-start: var(--space-3);
  }
}


/* --------------------------------------------------------------------------
   4. PREVENT TEXT SELECTION ON INTERACTIVE ELEMENTS
   -------------------------------------------------------------------------- */

button,
[role="button"],
.card,
.btn,
.tab,
.chip,
.nav-item,
.interactive,
summary {
  -webkit-user-select: none;
  user-select: none;
}


/* --------------------------------------------------------------------------
   5. iOS-STYLE BUTTON PRESS FEEDBACK
   -------------------------------------------------------------------------- */

button,
[role="button"],
.btn,
.card-pressable,
.interactive {
  transition: transform 180ms cubic-bezier(0.2, 0, 0, 1),
              opacity 180ms cubic-bezier(0.2, 0, 0, 1);
}

button:active,
[role="button"]:active,
.btn:active,
.card-pressable:active,
.interactive:active {
  transform: scale(0.97);
  opacity: 0.85;
}


/* --------------------------------------------------------------------------
   6. STATUS BAR BLUR OVERLAY (Standalone PWA)
   -------------------------------------------------------------------------- */

.ios-status-blur {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: 9999;
  block-size: env(safe-area-inset-top, 0px);
  background: oklch(from var(--bg-deep) l c h / 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   7. SAFE AREA PADDING
   -------------------------------------------------------------------------- */

.safe-area-pad {
  padding-block-start: env(safe-area-inset-top, 0px);
  padding-block-end: env(safe-area-inset-bottom, 0px);
  padding-inline-start: env(safe-area-inset-right, 0px);  /* RTL: right = start */
  padding-inline-end: env(safe-area-inset-left, 0px);      /* RTL: left = end */
}

.safe-top    { padding-block-start: env(safe-area-inset-top, 0px); }
.safe-bottom { padding-block-end: env(safe-area-inset-bottom, 0px); }
.safe-inline {
  padding-inline-start: env(safe-area-inset-right, 0px);
  padding-inline-end: env(safe-area-inset-left, 0px);
}


/* --------------------------------------------------------------------------
   8. TYPOGRAPHY CLASSES
   -------------------------------------------------------------------------- */

/* --- Scale --- */
.text-xs   { font-size: 0.694rem; line-height: 1.6; }   /* ~12.5px */
.text-sm   { font-size: 0.833rem; line-height: 1.7; }   /* ~15px   */
.text-base { font-size: 1rem;     line-height: 1.9; }   /* 18px    */
.text-md   { font-size: 1.125rem; line-height: 1.8; }   /* ~20px   */
.text-lg   { font-size: 1.333rem; line-height: 1.7; }   /* ~24px   */
.text-xl   { font-size: 1.777rem; line-height: 1.5; }   /* ~32px   */
.text-2xl  { font-size: 2.369rem; line-height: 1.3; }   /* ~42px   */
.text-3xl  { font-size: 3.157rem; line-height: 1.2; }   /* ~56px   */
.text-hero { font-size: clamp(2.4rem, 6vw, 4.2rem); line-height: 1.15; }

/* --- Specialist typefaces --- */
.text-quran {
  font-family: var(--font-quran);
  font-size: 1.5rem;
  line-height: 2.4;
  letter-spacing: 0.01em;
  font-feature-settings: "liga" 1, "calt" 1;
}

.text-display {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.text-arabic-body {
  font-family: var(--font-body);
  line-height: 1.9;
  font-feature-settings: "kern" 1;
}

/* --- Eyebrow / label --- */
.eyebrow {
  font-size: 0.694rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.4;
  color: var(--accent-amber);
}


/* --------------------------------------------------------------------------
   9. UTILITY CLASSES
   -------------------------------------------------------------------------- */

/* Screen-reader only */
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Glassmorphism panel */
.glass {
  background: oklch(from var(--bg-surface) l c h / 0.45);
  -webkit-backdrop-filter: saturate(160%) blur(24px);
  backdrop-filter: saturate(160%) blur(24px);
  border: 1px solid oklch(100% 0 0 / 0.06);
  border-radius: 1rem;
}

/* SVG noise grain overlay */
.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* Ambient light glow at screen edges */
.ambient-light {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 0% 0%,   oklch(from var(--accent-amber) l c h / 0.06), transparent 60%),
    radial-gradient(ellipse 50% 50% at 100% 100%, oklch(from var(--accent-amber) l c h / 0.04), transparent 50%);
}


/* --------------------------------------------------------------------------
   10. FOCUS STATES — AMBER RING
   -------------------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent-amber);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Remove inner dotted border in Firefox */
::-moz-focus-inner {
  border: 0;
}


/* --------------------------------------------------------------------------
   11. SCROLLBAR STYLING
   -------------------------------------------------------------------------- */

/* Webkit / Blink */
::-webkit-scrollbar {
  inline-size: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: oklch(from var(--accent-amber) l c h / 0.35);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: oklch(from var(--accent-amber) l c h / 0.55);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: oklch(from var(--accent-amber) l c h / 0.35) transparent;
}


/* --------------------------------------------------------------------------
   12. SELECTION / HIGHLIGHT
   -------------------------------------------------------------------------- */

::selection {
  background: oklch(from var(--accent-amber) l c h / 0.3);
  color: var(--fg-primary);
}

::-moz-selection {
  background: oklch(from var(--accent-amber) l c h / 0.3);
  color: var(--fg-primary);
}


/* --------------------------------------------------------------------------
   13. SKELETON LOADING ANIMATION
   -------------------------------------------------------------------------- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: oklch(from var(--bg-surface) l c h / 0.6);
  border-radius: 0.5rem;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    oklch(100% 0 0 / 0.04) 40%,
    oklch(100% 0 0 / 0.08) 50%,
    oklch(100% 0 0 / 0.04) 60%,
    transparent 100%
  );
  animation: shimmer 1500ms ease-in-out infinite;
}

/* RTL: sweep from right to left */
[dir="rtl"] .skeleton::after {
  animation-name: shimmer-rtl;
}


/* --------------------------------------------------------------------------
   14. KEYFRAME ANIMATIONS
   -------------------------------------------------------------------------- */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(1.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideFromRight {
  from {
    opacity: 0;
    transform: translateX(2rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideFromLeft {
  from {
    opacity: 0;
    transform: translateX(-2rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

@keyframes shimmer-rtl {
  from { transform: translateX(100%); }
  to   { transform: translateX(-100%); }
}

@keyframes scroll-track {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}


/* --------------------------------------------------------------------------
   15. CSS SCROLL-DRIVEN ANIMATION — PROGRESS BAR
   -------------------------------------------------------------------------- */

.scroll-progress {
  position: fixed;
  inset-block-start: 0;
  inset-inline-start: 0;
  inset-inline-end: 0;
  block-size: 2px;
  background: var(--accent-amber);
  transform-origin: right; /* RTL: shrinks toward the left */
  animation: scroll-track linear;
  animation-timeline: scroll(root block);
  z-index: 10000;
  pointer-events: none;
}

/* LTR override if needed */
:root:not([dir="rtl"]) .scroll-progress {
  transform-origin: left;
}


/* --------------------------------------------------------------------------
   16. TOUCH OPTIMIZATION
   --------------------------------------------------------------------------
   Eliminate 300ms tap delay, ensure minimum 44x44px touch targets,
   prevent accidental zooms, and improve scroll behavior on touch.
   -------------------------------------------------------------------------- */

/* Eliminate double-tap-to-zoom delay on all interactive elements */
a,
button,
[role="button"],
input,
select,
textarea,
.btn,
.card,
.nav-item,
.interactive,
.tab,
.chip,
summary,
label {
  touch-action: manipulation;
}

/* Ensure minimum 44x44px touch targets (WCAG 2.5.5 AAA) */
@media (pointer: coarse) {
  button,
  [role="button"],
  .btn,
  .nav-item,
  .tab,
  .chip,
  a:not(.inline-link) {
    min-block-size: 44px;
    min-inline-size: 44px;
  }

  /* Slightly larger padding on touch for thumb comfort */
  .card {
    padding: var(--space-5, 20px);
  }

  /* Increase gaps between tappable items */
  .button-group,
  .chip-group,
  .tab-bar {
    gap: var(--space-3, 12px);
  }
}

/* Prevent pull-to-refresh on PWA main body (child containers can still scroll) */
html {
  overscroll-behavior-y: none;
}

/* Smooth momentum scrolling for all scrollable containers */
.scroll-container,
.horizontal-scroll,
[data-scroll] {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}


/* --------------------------------------------------------------------------
   17. TABLET / iPAD RESPONSIVE — 768px to 1024px
   -------------------------------------------------------------------------- */

@media (min-width: 768px) {
  :root {
    --space-page-x: var(--space-8);
  }

  /* Bottom nav grows for tablet thumb reach */
  .bottom-nav {
    block-size: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .nav-item {
    gap: 4px;
  }

  .nav-icon {
    font-size: 1.4rem;
  }

  .nav-label {
    font-size: 0.7rem;
  }
}

@media (min-width: 1024px) {
  :root {
    --space-page-x: var(--space-10);
  }
}


/* --------------------------------------------------------------------------
   18. LIGHT THEME — Base Overrides
   -------------------------------------------------------------------------- */

[data-theme="light"] body {
  background-color: var(--bg-deep);
  color: var(--fg-primary);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: oklch(55% 0.15 55 / 0.3);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: oklch(55% 0.15 55 / 0.5);
}

[data-theme="light"] * {
  scrollbar-color: oklch(55% 0.15 55 / 0.3) transparent;
}

/* Allow text selection/callout on content areas */
.text-quran,
.athkar-text,
.dua-text,
.tafseer-ayah-text,
.tafsir-body,
p,
.ayah {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}


/* --------------------------------------------------------------------------
   19. iPAD / TABLET ENHANCEMENTS — 768px+
   -------------------------------------------------------------------------- */

/* iPad trackpad/mouse hover states */
@media (hover: hover) and (pointer: fine) {
  .athkar-cat-card:hover,
  .duas-cat-card:hover,
  .tools-cat-card:hover,
  .surah-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px oklch(0% 0 0 / 0.12);
  }

  .bento-card:hover {
    transform: translateY(-1px);
  }

  /* Cursor pointer for clickable cards */
  .athkar-cat-card,
  .duas-cat-card,
  .tools-cat-card,
  .surah-card,
  .bento-card {
    cursor: pointer;
  }
}

/* iPad reading width constraint for long text (NOT Quran/tafseer/athkar — those go full-width) */
@media (min-width: 768px) {
  .duas-reader-content {
    max-inline-size: 720px;
    margin-inline: auto;
  }
}

@media (min-width: 1024px) {
  .duas-reader-content {
    max-inline-size: 800px;
  }
}


/* --------------------------------------------------------------------------
   20. REDUCED MOTION — GLOBAL
   -------------------------------------------------------------------------- */

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


/* Auto light theme via OS preference */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) body {
    background-color: oklch(96% 0.010 75);
    color: oklch(15% 0.015 55);
  }

  :root:not([data-theme]) ::-webkit-scrollbar-thumb {
    background: oklch(55% 0.15 55 / 0.3);
  }
}
