/* ============================================
   Base — Reset, typography, layout primitives
   ============================================ */

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

html[lang="ar"] { font-family: var(--font-ar-secondary); }
html[lang="en"] { font-family: var(--font-en-secondary); }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

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

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover { color: var(--accent); }

ul, ol { list-style: none; }

/* ===== Headings ===== */
h1, h2, h3, h4, h5, h6 {
  line-height: var(--lh-tight);
  font-weight: 700;
  color: var(--text-primary);
}
[lang="ar"] h1, [lang="ar"] h2, [lang="ar"] h3, [lang="ar"] h4 {
  font-family: var(--font-ar-primary);
  letter-spacing: 0;
}
[lang="en"] h1, [lang="en"] h2, [lang="en"] h3 {
  font-family: var(--font-en-primary);
}

h1 { font-size: clamp(2rem, 5vw, var(--fs-4xl)); }
h2 { font-size: clamp(1.6rem, 3.5vw, var(--fs-2xl)); }
h3 { font-size: clamp(1.3rem, 2.5vw, var(--fs-xl)); }
h4 { font-size: var(--fs-lg); }

p { color: var(--text-secondary); line-height: var(--lh-relaxed); }

/* ===== Selection ===== */
::selection {
  background: var(--accent);
  color: var(--color-black);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

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

/* ===== Container ===== */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container-narrow { max-width: var(--container-narrow); }
.container-wide { max-width: var(--container-wide); }

/* ===== Sections ===== */
.section {
  padding-block: clamp(3rem, 8vw, var(--sp-24));
  position: relative;
}
.section-sm { padding-block: clamp(2rem, 5vw, var(--sp-16)); }

.section-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--border-default);
  border-radius: var(--r-pill);
  background: var(--bg-glass);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.section-eyebrow::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
}

.section-title {
  margin-top: var(--sp-4);
  margin-bottom: var(--sp-4);
  max-width: 22ch;
}
.section-lead {
  max-width: 60ch;
  font-size: var(--fs-md);
  color: var(--text-secondary);
}

/* ===== Grid ===== */
.grid { display: grid; gap: var(--sp-6); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

@media (min-width: 768px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ===== Utilities ===== */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }
.text-center { text-align: center; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-8 { margin-bottom: var(--sp-8); }
.mb-12 { margin-bottom: var(--sp-12); }
.mt-4 { margin-top: var(--sp-4); }
.mt-8 { margin-top: var(--sp-8); }
.text-accent { color: var(--accent); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ===== Decorative — Aurora background ===== */
.aurora {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.aurora::before,
.aurora::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.55;
}
.aurora::before {
  top: -10%;
  inset-inline-start: -15%;
  width: 60vw;
  height: 60vw;
  background: radial-gradient(circle, var(--color-green) 0%, transparent 60%);
  animation: aurora-drift 18s ease-in-out infinite alternate;
}
.aurora::after {
  bottom: -20%;
  inset-inline-end: -10%;
  width: 55vw;
  height: 55vw;
  background: radial-gradient(circle, #006633 0%, transparent 65%);
  animation: aurora-drift 22s ease-in-out infinite alternate-reverse;
}
@keyframes aurora-drift {
  0% { transform: translate(0,0) scale(1); }
  100% { transform: translate(8%, -6%) scale(1.1); }
}

/* ===== Noise overlay ===== */
.noise {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/></svg>");
  z-index: 1;
}

/* ============================================
   Accessibility (WCAG 2.1 AA)
   ============================================ */

/* Skip-link — visually hidden until focused */
.skip-link {
  position: fixed;
  top: -100px;
  inset-inline-start: var(--sp-3);
  z-index: 10000;
  padding: var(--sp-3) var(--sp-5);
  background: var(--accent);
  color: var(--color-black);
  border-radius: var(--r-md);
  font-weight: 700;
  text-decoration: none;
  font-size: var(--fs-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--sp-3); outline: 0; }

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus-visible — keyboard navigation only */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:where(.btn, .filter-chip, .profile-tab, .stepper-step, .track-card):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
/* Don't apply double outline on inputs that already have border */
:where(.input, .select, .textarea):focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Toast — make it announce to screen readers */
.toast { /* additional a11y semantics applied in JS via role="status" */ }

/* Reduced motion — kill non-essential animations */
@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;
  }
  html { scroll-behavior: auto; }
}
