/* Variables and global styles - Production Optimized */
:root {
    /* Primary Colors */
    --primary-color: #6c63ff;
    --primary-color-dark: #5a52d5;
    --primary-color-light: #8b84ff;
    --secondary-color: #f5f5f5;

    /* Light Mode Colors */
    --text-color: #1a1a1a;
    --text-light: #4a4a4a;
    --text-lighter: #888888;
    --background-light: #ffffff;

    /* Dark Mode Colors */
    --background-dark: #0a0a0a;
    --background-dark-lighter: #1a1a1a;
    --text-dark: #f5f5f5;
    --text-dark-light: #b0b0b0;

    /* Shadows */
    --shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.2);

    /* Transitions */
    --transition: all 0.3s ease;
    --transition-fast: all 0.15s ease;
    --transition-slow: all 0.5s ease;
    --section-transition: transform 0.7s cubic-bezier(0.165, 0.84, 0.44, 1), opacity 0.7s cubic-bezier(0.165, 0.84, 0.44, 1);

    /* Spacing variables */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    --spacing-xxl: 4rem;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Typography - Vazirmatn applied universally with optimized fallback stack */
    --font-family-primary: 'Vazirmatn', 'Tahoma', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-family-secondary: 'Vazirmatn', 'Tahoma', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;
    --font-size-5xl: 3rem;
    --font-weight-light: 300;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Z-index layers */
    --z-below: -1;
    --z-normal: 1;
    --z-dropdown: 100;
    --z-sticky: 500;
    --z-fixed: 1000;
    --z-modal: 2000;
    --z-tooltip: 3000;

    /* Portfolio Blob Colors RGB values for rgba usage */
    --color-6c63ff-rgb: 108, 99, 255;
    --color-1a73e8-rgb: 26, 115, 232;
    --color-ff5252-rgb: 255, 82, 82;
    --color-2ca58d-rgb: 44, 165, 141;
    --color-9c27b0-rgb: 156, 39, 176;
    --color-fb8c00-rgb: 251, 140, 0;

    /* Mobile viewport height fix (set by JS) */
    --vh: 1vh;

    /* Accessibility - High contrast colors */
    --focus-outline: 3px solid rgba(108, 99, 255, 0.5);
    --focus-outline-offset: 2px;
    --focus-ring-color: #6c63ff;
    --focus-ring-opacity: 0.5;

    /* Performance optimization */
    --will-change-transform: transform;
    --will-change-opacity: opacity;
    --backface-hidden: hidden;

    /* Container widths */
    --container-sm: 640px;
    --container-md: 768px;
    --container-lg: 1024px;
    --container-xl: 1280px;
    --container-2xl: 1536px;

    /* Breakpoints for JS */
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
}

/* Improved focus styles for accessibility */
*:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
    border-radius: var(--radius-sm);
}

/* Hide focus outline when not using keyboard */
body:not(.user-is-tabbing) *:focus {
    outline: none;
}

/* Improve text readability */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    text-size-adjust: 100%;
}

/* Reduce motion for accessibility */
@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;
    }
}

/* High contrast mode support - Enhanced for accessibility */
@media (prefers-contrast: more) {
    :root {
        --focus-outline: 3px solid #000;
        --shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
        --text-color: #000;
        --text-light: #333;
        --text-lighter: #666;
    }

    body.dark-mode {
        --focus-outline: 3px solid #fff;
        --text-dark: #fff;
        --text-dark-light: #ddd;
        --background-dark: #000;
    }
}

/* Forced colors mode support (Windows High Contrast) */
@media (forced-colors: active) {
    :root {
        --primary-color: LinkText;
        --text-color: CanvasText;
        --background-light: Canvas;
        --focus-outline: 2px solid Highlight;
    }

    .btn {
        border: 1px solid currentColor;
    }

    .hero-image img,
    .blob {
        forced-color-adjust: none;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Apply Vazirmatn font universally to ensure consistency across all elements */
    font-family: var(--font-family-primary) !important;
}

body {
    font-family: var(--font-family-primary);
    line-height: var(--line-height-normal);
    color: var(--text-color);
    background-color: var(--background-light);
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    scroll-behavior: smooth;
    min-height: 100vh;
    /* CSS containment for better performance */
    contain: layout style;
}

body.dark-mode {
    color: var(--text-dark);
    background-color: var(--background-dark);
}

/* Ensure all headings, paragraphs, and text elements use Vazirmatn with improved fallback */
h1, h2, h3, h4, h5, h6, p, a, span, div, li, button, input, textarea, select, label {
    font-family: var(--font-family-primary) !important;
}

.container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

@media (min-width: 1536px) {
    .container {
        max-width: var(--container-2xl);
    }
}

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    margin-bottom: var(--spacing-md);
    color: inherit;
}

h1 {
    font-size: clamp(2rem, 5vw, var(--font-size-5xl));
}

h2 {
    font-size: clamp(1.5rem, 4vw, var(--font-size-3xl));
    text-align: center;
}

h3 {
    font-size: var(--font-size-2xl);
}

h4 {
    font-size: var(--font-size-xl);
}

p {
    margin-bottom: var(--spacing-md);
    line-height: var(--line-height-relaxed);
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: var(--transition);
}

a:hover {
    opacity: 0.8;
}

a:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
}

/* Improved button styles */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    border: none;
    font-size: var(--font-size-base);
    line-height: 1;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.primary {
    background-color: var(--primary-color);
    color: white;
}

.secondary {
    background-color: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
}

.section-intro {
    text-align: center;
    max-width: 700px;
    margin: 0 auto var(--spacing-xl) auto;
    color: var(--text-light);
    line-height: var(--line-height-relaxed);
}

body.dark-mode .section-intro {
    color: var(--text-dark-light);
}

/* Page sectioning for smooth scrolling */
html, body {
    scroll-behavior: smooth;
    overflow-x: hidden;
    /* Prevent partial scrolling between sections */
    overflow-y: hidden;
}

/* Section active states */
section.active {
    transform: translateY(0) !important;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.08);
}

/* Enhanced section content transitions */
section .container {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 1.2s cubic-bezier(0.165, 0.84, 0.44, 1),
    transform 1.2s cubic-bezier(0.165, 0.84, 0.44, 1);
    transition-delay: 0.2s;
}

section.active .container {
    opacity: 1;
    transform: translateY(0);
}

/* Skip Link for Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--primary-color);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 600;
    z-index: var(--z-modal);
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 10px;
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
}

body.dark-mode .skip-link {
    background-color: #a395ff;
    color: #000;
}

/* Utility Classes for Performance */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-load.loaded {
    opacity: 1;
}

/* Prevent layout shift */
.aspect-ratio-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-ratio-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1 / 1;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Loading states */
.loading {
    pointer-events: none;
    opacity: 0.6;
    cursor: not-allowed;
}

/* No JavaScript fallback */
body[data-js="false"] .js-only {
    display: none !important;
}

/* Optimized animations for performance */
@media (prefers-reduced-motion: no-preference) {
    .fade-in {
        animation: fadeIn 0.5s ease-in-out;
    }

    .slide-up {
        animation: slideUp 0.5s ease-out;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Print styles */
@media print {
    *,
    *::before,
    *::after {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    a,
    a:visited {
        text-decoration: underline;
    }

    a[href]::after {
        content: " (" attr(href) ")";
    }

    abbr[title]::after {
        content: " (" attr(title) ")";
    }

    thead {
        display: table-header-group;
    }

    tr,
    img {
        page-break-inside: avoid;
    }

    p,
    h2,
    h3 {
        orphans: 3;
        widows: 3;
    }

    h2,
    h3 {
        page-break-after: avoid;
    }
}