/* Compatibility CSS - Basic browser compatibility styles */

/* CSS Custom Properties for theming */
:root {
    --primary-color: #2e8b57;
    --primary-dark: #1e3a2a;
    --accent-color: #ffd93d;
    --text-color: #333333;
    --text-light: #5a7d5a;
    --bg-color: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
    --border-radius: 8px;
}

/* Dark mode variables */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #88c9a1;
        --primary-dark: #1e3a2a;
        --accent-color: #ffd93d;
        --text-color: #f8f9fa;
        --text-light: #dee2e6;
        --bg-color: #212529;
        --shadow-color: rgba(0, 0, 0, 0.3);
    }
}

/* CSS Feature Detection */
@supports (display: grid) {
    .supports-grid {
        display: grid;
    }
}

@supports (display: flexbox) {
    .supports-flex {
        display: flex;
    }
}

@supports (scroll-behavior: smooth) {
    .supports-smooth-scroll {
        scroll-behavior: smooth;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .touch-optimized {
        min-height: 44px;
        padding: 12px 24px;
        font-size: 16px;
    }
}

/* High DPI screen optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .high-dpi-optimized {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .reduced-motion {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .high-contrast {
        background: #ffffff;
        color: #000000;
        border: 2px solid #000000;
    }
    
    .high-contrast-accent {
        background: #000000;
        color: #ffffff;
    }
}

/* CSS Grid fallbacks */
.no-cssgrid .grid-fallback {
    display: block;
}

.no-cssgrid .grid-fallback > * {
    float: left;
    width: 33.33%;
    box-sizing: border-box;
}

.no-cssgrid .grid-fallback::after {
    content: "";
    display: table;
    clear: both;
}

/* Flexbox fallbacks */
.no-flexbox .flex-fallback {
    display: block;
}

.no-flexbox .flex-fallback > * {
    display: inline-block;
    vertical-align: top;
    width: 33.33%;
    box-sizing: border-box;
}

/* CSS Variables fallback */
.color-fallback {
    color: #333333; /* Fallback for var(--text-color) */
    color: var(--text-color, #333333);
}

/* Modern focus styles with fallbacks */
.focus-fallback:focus {
    outline: 2px solid #2e8b57;
    outline-offset: 2px;
}

/* Accessibility improvements */
.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;
}

/* Skip links for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2e8b57;
    color: white;
    padding: 8px;
    text-decoration: none;
    font-weight: bold;
    z-index: 100;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
}

/* ARIA live regions */
[aria-live] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

[aria-live].visible {
    position: static;
    width: auto;
    height: auto;
    padding: 8px;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 1px solid #ffd93d;
    border-radius: 4px;
    background: #fff3cd;
    color: #856404;
}

/* CSS Grid Layout fallbacks */
.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

/* Flexbox Layout fallbacks */
.flex-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Scroll snap fallbacks */
.scroll-snap-fallback {
    scroll-snap-type: x mandatory;
    overflow-x: auto;
}

.no-scroll-snap .scroll-snap-fallback {
    scroll-snap-type: none;
    overflow-x: visible;
}

/* CSS aspect-ratio fallback */
.aspect-ratio-fallback {
    aspect-ratio: 16 / 9;
}

.no-aspect-ratio .aspect-ratio-fallback::before {
    content: '';
    display: block;
    padding-bottom: 56.25%; /* 9/16 = 0.5625 */
}

.no-aspect-ratio .aspect-ratio-fallback > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* CSS backdrop-filter fallback */
.backdrop-filter-fallback {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

.no-backdrop-filter .backdrop-filter-fallback {
    background: rgba(255, 255, 255, 0.95);
}

/* CSS clip-path fallback */
.clip-path-fallback {
    clip-path: circle(50% at 50% 50%);
}

.no-clip-path .clip-path-fallback {
    border-radius: 50%;
}

/* CSS filter effects fallback */
.filter-fallback {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.no-cssfilters .filter-fallback {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* CSS blend modes fallback */
.blend-mode-fallback {
    mix-blend-mode: multiply;
}

.no-mixblendmode .blend-mode-fallback {
    opacity: 0.8;
}

/* CSS will-change optimization */
.will-change-optimized {
    will-change: transform;
}

/* CSS contain for performance */
.contain-optimized {
    contain: layout style paint;
}

/* CSS logical properties fallback */
.logical-props-fallback {
    margin-inline-start: 1rem;
    padding-inline-end: 2rem;
    border-start-start-radius: 8px;
}

.no-logical-props .logical-props-fallback {
    margin-left: 1rem;
    padding-right: 2rem;
    border-top-left-radius: 8px;
}

/* Container queries fallback */
@supports not (container-type: inline-size) {
    .container-query-fallback {
        width: 100%;
    }
    
    @media (min-width: 300px) {
        .container-query-fallback {
            width: calc(50% - 0.5rem);
        }
    }
    
    @media (min-width: 600px) {
        .container-query-fallback {
            width: calc(33.333% - 0.667rem);
        }
    }
}

/* Final fallback styles */
.fallback-final {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, sans-serif;
    line-height: 1.5;
    color: var(--text-color, #333333);
    background: var(--bg-color, #ffffff);
}

/* Reset for compatibility */
*,
*::before,
*::after {
    box-sizing: inherit;
}

html {
    box-sizing: border-box;
    font-size: 16px;
    scroll-behavior: smooth;
}

/* Ensure proper focus management */
:focus {
    outline: 2px solid var(--accent-color, #ffd93d);
    outline-offset: 2px;
}

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

/* High performance animations */
.performance-optimized {
    transform: translateZ(0);
    will-change: transform;
    contain: layout style paint;
}

/* Memory-efficient images */
.memory-optimized img {
    max-width: 100%;
    height: auto;
}