/* ============================================
   BASE.CSS - Variables, Reset, Typography, RTL
   InterSystems IRIS Arabic Academy
   ============================================ */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&family=Noto+Kufi+Arabic:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* CSS Custom Properties */
:root {
  /* Background colors */
  --bg-deep: #060b18;
  --bg-primary: #0a1128;
  --bg-surface: #111d3a;
  --bg-elevated: #162040;
  --bg-card: #1a2548;
  --bg-card-hover: #1f2d55;
  --bg-input: #0d1630;

  /* Accent colors */
  --gold: #d4a843;
  --gold-light: #e8c76a;
  --gold-dark: #b8922e;
  --teal: #2ec4b6;
  --teal-light: #4dd9cc;
  --teal-dark: #1fa89b;
  --blue: #3a86ff;
  --blue-light: #5a9dff;
  --blue-dark: #2070e0;
  --purple: #8338ec;
  --purple-light: #9b5cf0;
  --purple-dark: #6c20d0;
  --rose: #ff006e;
  --rose-light: #ff3d8e;
  --rose-dark: #d0005a;
  --green: #06d6a0;
  --green-light: #2ee0b5;
  --green-dark: #05b585;

  /* Text colors */
  --text-primary: #e8eaf0;
  --text-secondary: #9aa3b8;
  --text-muted: #6b7590;
  --text-heading: #ffffff;
  --text-link: var(--teal);
  --text-code: var(--gold-light);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --border-accent: rgba(212, 168, 67, 0.3);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-gold: 0 0 20px rgba(212, 168, 67, 0.2);
  --shadow-glow-teal: 0 0 20px rgba(46, 196, 182, 0.2);
  --shadow-glow-blue: 0 0 20px rgba(58, 134, 255, 0.2);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  --space-4xl: 6rem;

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Font families */
  --font-body: 'IBM Plex Sans Arabic', sans-serif;
  --font-heading: 'Noto Kufi Arabic', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Font sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-index */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;
  --z-skip: 600;

  /* Container */
  --container-max: 1280px;
  --container-padding: 1.5rem;
}

/* Light theme overrides */
[data-theme="light"] {
  --bg-deep: #f0f2f7;
  --bg-primary: #f8f9fc;
  --bg-surface: #ffffff;
  --bg-elevated: #f5f6fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f2f7;
  --bg-input: #f0f2f7;
  --text-primary: #1a1d2e;
  --text-secondary: #4a5068;
  --text-muted: #8890a5;
  --text-heading: #0a1128;
  --text-code: #6c20d0;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-default: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);
  --border-accent: rgba(212, 168, 67, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-glow-gold: 0 0 20px rgba(212, 168, 67, 0.15);
  --shadow-glow-teal: 0 0 20px rgba(46, 196, 182, 0.15);
  --shadow-glow-blue: 0 0 20px rgba(58, 134, 255, 0.15);
}

/* CSS Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-deep);
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  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.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

/* Ambient gradient background */
body::after {
  content: '';
  position: fixed;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 70% 20%, rgba(58, 134, 255, 0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 30% 80%, rgba(131, 56, 236, 0.04) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 70%, rgba(46, 196, 182, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* Ensure content is above overlays */
body > * {
  position: relative;
  z-index: 2;
}

/* Skip to content link */
.skip-link {
  position: fixed;
  top: -100%;
  right: 0;
  background: var(--gold);
  color: var(--bg-deep);
  padding: var(--space-sm) var(--space-lg);
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  z-index: var(--z-skip);
  transition: top var(--transition-fast);
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text-heading);
  line-height: 1.3;
  font-weight: 700;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
}

a {
  color: var(--teal);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--teal-light);
}

a:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

strong, b { font-weight: 600; }

em, i { font-style: italic; }

ul, ol {
  padding-right: var(--space-xl);
  padding-left: 0;
  margin-bottom: var(--space-md);
}

li {
  margin-bottom: var(--space-xs);
  color: var(--text-secondary);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elevated);
  color: var(--text-code);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  overflow-x: auto;
  margin-bottom: var(--space-lg);
  direction: ltr;
  text-align: left;
  position: relative;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

blockquote {
  border-right: 4px solid var(--gold);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  color: var(--text-secondary);
  font-style: italic;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-lg);
  direction: rtl;
}

th, td {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-default);
  text-align: right;
}

th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-heading);
  font-family: var(--font-heading);
}

tr:nth-child(even) {
  background: var(--bg-surface);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

hr {
  border: none;
  height: 1px;
  background: var(--border-default);
  margin: var(--space-2xl) 0;
}

/* Selection */
::selection {
  background: rgba(46, 196, 182, 0.3);
  color: var(--text-heading);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-card);
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Animations */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-30px); }
  to { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes ringProgress {
  from { stroke-dashoffset: 283; }
}

.animate-fade-up {
  animation: fadeUp 0.6s ease forwards;
}

.animate-fade-down {
  animation: fadeDown 0.6s ease forwards;
}

.animate-fade-in {
  animation: fadeIn 0.4s ease forwards;
}

.animate-scale-in {
  animation: scaleIn 0.4s ease forwards;
}

.animate-float {
  animation: float 3s ease-in-out infinite;
}

.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

.animate-shimmer {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
}

/* Utility classes */
.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;
}

.text-gold { color: var(--gold); }
.text-teal { color: var(--teal); }
.text-blue { color: var(--blue); }
.text-purple { color: var(--purple); }
.text-rose { color: var(--rose); }
.text-green { color: var(--green); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-left { text-align: left; }

.font-heading { font-family: var(--font-heading); }
.font-mono { font-family: var(--font-mono); }

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-padding);
}

.glass {
  background: rgba(26, 37, 72, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-default);
}

.gradient-text {
  background: linear-gradient(135deg, var(--gold), var(--teal));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --container-padding: 1rem;
  }

  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  h4 { font-size: var(--text-lg); }
}

@media (max-width: 480px) {
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
}

/* Print styles */
@media print {
  body {
    background: white;
    color: black;
    direction: rtl;
  }

  body::before, body::after {
    display: none;
  }

  .no-print, nav, footer, .skip-link, .theme-toggle, .mobile-menu-btn {
    display: none !important;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  pre, code {
    background: #f5f5f5;
    border: 1px solid #ddd;
    color: black;
  }

  h1, h2, h3, h4 {
    color: black;
    page-break-after: avoid;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  * {
    box-shadow: none !important;
  }
}
