/**
 * Performance Optimization CSS
 * Critical CSS and performance-focused styles
 */

/* Critical path CSS - above the fold styles */
.critical-path {
    /* Essential header styles */
    .site-header {
        background-color: var(--bg-color);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    
    /* Essential hero section styles */
    .hero {
        background: linear-gradient(135deg, var(--primary-green-light) 0%, var(--primary-green) 100%);
        color: white;
        min-height: 60vh;
        display: flex;
        align-items: center;
    }
    
    /* Essential typography */
    .hero-title {
        font-size: clamp(2rem, 4vw, 3.5rem);
        font-weight: 700;
        line-height: 1.2;
        margin-bottom: 1rem;
    }
}

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

/* GPU acceleration for smooth animations */
.nav-toggle,
.btn,
.card,
.project-card,
.service-card,
.news-card {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimize images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Lazy loading optimization */
.lazy {
    opacity: 0;
    transition: opacity 0.3s;
}

.lazy.loaded {
    opacity: 1;
}

/* Preload critical resources */
.preload-bg {
    background-image: url('data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="1" height="1"%3E%3C/svg%3E');
}

/* Reduce 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;
}

/* Optimize 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;
    }
}

/* Container query optimization */
.container {
    container-type: inline-size;
}

/* Critical font display */
@font-face {
    font-family: 'Noto Sans JP';
    font-display: swap;
    src: url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&display=swap');
}

/* Optimize scrolling performance */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    /* overflow-scrolling: touch; */
}

/* Optimize paint performance */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Remove will-change after animation */
.animation-complete {
    will-change: auto;
}

/* Optimize table performance */
.table-fixed {
    table-layout: fixed;
}

/* Optimize form performance */
.form-input {
    contain: layout style paint;
}

/* Critical web vitals optimizations */
.cls-prevention {
    min-height: 200px; /* Prevent layout shift */
}

/* Optimize third-party content */
.third-party-container {
    contain: layout style paint;
    content-visibility: auto;
    contain-intrinsic-size: 300px;
}

/* Resource hints for performance */
.resource-hint {
    display: none;
}

/* Optimize background images */
.bg-optimized {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: scroll; /* Avoid fixed for mobile performance */
}

/* Optimize flexbox layouts */
.flex-optimized {
    display: flex;
    flex-direction: column;
    min-height: 0; /* Prevent flex items from growing */
}

@media (min-width: 768px) {
    .flex-optimized {
        flex-direction: row;
    }
}

/* Optimize grid layouts */
.grid-optimized {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

/* Print optimizations */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-optimized {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    .auto-dark {
        background-color: #1a1a1a;
        color: #ffffff;
    }
    
    .auto-dark img {
        opacity: 0.8;
        transition: opacity 0.3s ease;
    }
    
    .auto-dark img:hover {
        opacity: 1;
    }
}

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

/* Optimize scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: var(--primary-green);
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--primary-green-dark);
}

/* Optimize focus management */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-green);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 1000;
    border-radius: 4px;
}

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

/* Performance monitoring */
.perf-mark {
    display: none;
}