/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Custom Properties */
:root {
    /* Colors */
    --color-primary: #1a365d;
    --color-secondary: #ff6b35;
    --color-accent: #38b2ac;
    --color-success: #48bb78;
    --color-warning: #ed8936;

    /* Neutrals */
    --color-white: #ffffff;
    --color-gray-50: #f7fafc;
    --color-gray-100: #edf2f7;
    --color-gray-200: #e2e8f0;
    --color-gray-300: #cbd5e0;
    --color-gray-400: #a0aec0;
    --color-gray-500: #718096;
    --color-gray-600: #4a5568;
    --color-gray-700: #2d3748;
    --color-gray-800: #1a202c;
    --color-gray-900: #171923;

    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-heading: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* Font Sizes */
    --text-xs: 0.75rem;
    /* 12px */
    --text-sm: 0.875rem;
    /* 14px */
    --text-base: 1rem;
    /* 16px */
    --text-lg: 1.125rem;
    /* 18px */
    --text-xl: 1.25rem;
    /* 20px */
    --text-2xl: 1.5rem;
    /* 24px */
    --text-3xl: 1.875rem;
    /* 30px */
    --text-4xl: 2.25rem;
    /* 36px */
    --text-5xl: 3rem;
    /* 48px */
    --text-6xl: 3.75rem;
    /* 60px */

    /* Spacing */
    --space-1: 0.25rem;
    /* 4px */
    --space-2: 0.5rem;
    /* 8px */
    --space-3: 0.75rem;
    /* 12px */
    --space-4: 1rem;
    /* 16px */
    --space-5: 1.25rem;
    /* 20px */
    --space-6: 1.5rem;
    /* 24px */
    --space-8: 2rem;
    /* 32px */
    --space-10: 2.5rem;
    /* 40px */
    --space-12: 3rem;
    /* 48px */
    --space-16: 4rem;
    /* 64px */
    --space-20: 5rem;
    /* 80px */
    --space-24: 6rem;
    /* 96px */
    --space-32: 8rem;
    /* 128px */

    /* Breakpoints */
    --bp-sm: 640px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --bp-xl: 1280px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;

    /* Transitions */
    --transition-fast: 150ms ease-out;
    --transition-base: 200ms ease-out;
    --transition-slow: 300ms ease-out;
}

/* Base Typography */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-gray-700);
    background-color: var(--color-white);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: 0;
    /* Hero section handles its own padding */
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-gray-900);
    margin-bottom: var(--space-4);
}

h1 {
    font-size: var(--text-5xl);
}

h2 {
    font-size: var(--text-4xl);
}

h3 {
    font-size: var(--text-3xl);
}

h4 {
    font-size: var(--text-2xl);
}

h5 {
    font-size: var(--text-xl);
}

h6 {
    font-size: var(--text-lg);
}

/* Paragraphs */
p {
    margin-bottom: var(--space-4);
}

/* Links */
a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-base);
}

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

/* Override global link styles for navigation */
.nav__link,
.nav__link:hover,
.nav__link:visited,
.nav__link:focus,
.nav__link:active {
    text-decoration: none !important;
    border-bottom: none !important;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
}

@media (min-width: 768px) {
    .container {
        padding: 0 var(--space-8);
    }
}

@media (min-width: 1024px) {
    .container {
        padding: 0 var(--space-12);
    }
}

/* Skip Link for Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-primary);
    color: var(--color-white);
    padding: 8px;
    text-decoration: none;
    border-radius: var(--radius-md);
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

/* Section Titles */
.section-title {
    text-align: center;
    margin-bottom: var(--space-16);
    font-size: var(--text-4xl);
    font-weight: 700;
    color: var(--color-primary);
}

@media (min-width: 768px) {
    .section-title {
        font-size: var(--text-5xl);
    }
}

/* Responsive Typography */
@media (max-width: 767px) {
    :root {
        --text-5xl: 2.5rem;
        /* 40px */
        --text-4xl: 2rem;
        /* 32px */
        --text-3xl: 1.5rem;
        /* 24px */
    }

    .container {
        padding: 0 var(--space-4);
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.font-medium {
    font-weight: 500;
}

.text-primary {
    color: var(--color-primary);
}

.text-secondary {
    color: var(--color-secondary);
}

.text-accent {
    color: var(--color-accent);
}

.text-success {
    color: var(--color-success);
}

.bg-primary {
    background-color: var(--color-primary);
}

.bg-secondary {
    background-color: var(--color-secondary);
}

.bg-gray-50 {
    background-color: var(--color-gray-50);
}

.bg-gray-100 {
    background-color: var(--color-gray-100);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-8 {
    margin-bottom: var(--space-8);
}

.mb-16 {
    margin-bottom: var(--space-16);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mt-8 {
    margin-top: var(--space-8);
}

.mt-16 {
    margin-top: var(--space-16);
}

.p-4 {
    padding: var(--space-4);
}

.p-6 {
    padding: var(--space-6);
}

.p-8 {
    padding: var(--space-8);
}

.rounded {
    border-radius: var(--radius-md);
}

.rounded-lg {
    border-radius: var(--radius-lg);
}

.rounded-xl {
    border-radius: var(--radius-xl);
}

.shadow-sm {
    box-shadow: var(--shadow-sm);
}

.shadow-md {
    box-shadow: var(--shadow-md);
}

.shadow-lg {
    box-shadow: var(--shadow-lg);
}

.shadow-xl {
    box-shadow: var(--shadow-xl);
}

/* C
ross-browser compatibility fixes */

/* Safari-specific fixes */
@supports (-webkit-appearance: none) {

    .metric__value,
    .metric-card__number {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    .challenge-card {
        -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
    }

    .challenge-card__front,
    .challenge-card__back {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    .timeline::before {
        background: var(--color-gray-300);
    }

    .scroll-arrow {
        transform: rotate(45deg);
    }
}

/* Edge/IE compatibility */
@supports not (display: grid) {
    .hero__metrics {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }

    .metrics-grid {
        display: flex;
        flex-wrap: wrap;
    }

    .challenges__grid {
        display: flex;
        flex-wrap: wrap;
    }

    .metric,
    .metric-card,
    .challenge-card {
        flex: 1 1 300px;
        margin: var(--space-4);
    }
}

/* Flexbox fallbacks for older browsers */
@supports not (display: flex) {
    .nav__container {
        display: table;
        width: 100%;
    }

    .nav__brand,
    .nav__menu {
        display: table-cell;
        vertical-align: middle;
    }

    .nav__menu {
        text-align: right;
    }
}

/* CSS Grid fallbacks */
@supports not (display: grid) {
    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 20px;
    }

    .hero__metrics,
    .metrics-grid,
    .challenges__grid,
    .success-stories,
    .impact__grid {
        display: block;
    }

    .hero__metrics>*,
    .metrics-grid>*,
    .challenges__grid>*,
    .success-stories>*,
    .impact__grid>* {
        display: inline-block;
        width: calc(33.333% - 20px);
        margin: 10px;
        vertical-align: top;
    }

    @media (max-width: 768px) {

        .hero__metrics>*,
        .metrics-grid>*,
        .challenges__grid>*,
        .success-stories>*,
        .impact__grid>* {
            width: calc(100% - 20px);
        }
    }
}

/* Custom properties fallbacks for older browsers */
.hero {
    background: linear-gradient(135deg, #f7fafc 0%, #ffffff 100%);
}

.metric__value {
    color: #1a365d;
}

.metric__unit {
    color: #ff6b35;
}

.btn--primary {
    background: #ff6b35;
    border-color: #ff6b35;
}

.btn--primary:hover {
    background: #ed8936;
    border-color: #ed8936;
}

/* Webkit-specific optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .challenge-card {
        -webkit-perspective: 1000px;
        perspective: 1000px;
    }

    .timeline__marker {
        -webkit-transform: translateX(-50%);
        transform: translateX(-50%);
    }
}

/* Print styles */
@media print {

    .nav,
    .hero__scroll-indicator,
    .challenge-card__flip-btn,
    .scroll-progress {
        display: none !important;
    }

    .hero {
        min-height: auto;
        padding: 2cm 0;
    }

    .section-title {
        page-break-after: avoid;
    }

    .challenge-card,
    .metric-card,
    .success-story {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    body {
        font-size: 12pt;
        line-height: 1.4;
    }

    h1 {
        font-size: 24pt;
    }

    h2 {
        font-size: 20pt;
    }

    h3 {
        font-size: 16pt;
    }

    .contact__link {
        color: #000 !important;
        text-decoration: underline;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .hero::before {
        background-size: 50px 50px;
    }

    .timeline::before {
        width: 1px;
    }
}

/* Reduced data mode */
@media (prefers-reduced-data: reduce) {
    .hero::before {
        display: none;
    }

    .timeline-progress {
        display: none;
    }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {

    .metric,
    .challenge-card__front,
    .challenge-card__back,
    .metric-card {
        border: 1px solid;
    }

    .btn {
        border: 2px solid;
    }

    .hero::before,
    .timeline::before {
        display: none;
    }
}