/**
 * Error Handling and Graceful Degradation Styles
 * Provides fallback styles and loading indicators
 */

/* Image loading states */
img {
    /* Prevent layout shift during loading */
    max-width: 100%;
    height: auto;
}

img[loading="lazy"] {
    /* Placeholder background while loading */
    background: rgba(255, 255, 255, 0.05);
    min-height: 100px;
}

/* Loading indicator for images */
.duo-photo {
    position: relative;
    min-height: 200px;
}

.duo-photo img {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.duo-photo img.loaded,
.duo-photo img[loading="lazy"]:not([src=""]) {
    opacity: 1;
}

/* Loading spinner for images */
.duo-photo::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 2px solid var(--color-mid, #808080);
    border-top-color: var(--color-fg, #E0E0E0);
    border-radius: 50%;
    animation: image-loading-spin 1s linear infinite;
    opacity: 0.5;
}

.duo-photo img.loaded ~ ::before,
.duo-photo:has(img[src]) ::before {
    display: none;
}

@keyframes image-loading-spin {
    to { transform: rotate(360deg); }
}

/* Error state for images */
img[alt]:not([src]),
img[src=""]:after {
    content: attr(alt);
    display: block;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-mid, #808080);
    color: var(--color-mid, #808080);
    font-family: var(--font-body, monospace);
    font-size: 12px;
    text-align: center;
}

/* Fallback for missing fonts */
@supports not (font-family: 'Consolas') {
    body {
        font-family: 'Courier New', 'Courier', monospace;
    }
}

/* Reduced motion support */
@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;
    }
    
    /* Disable scanline animation */
    .scanlines {
        animation: none !important;
    }
    
    /* Disable glitch effects */
    .glitch,
    .glitch-element {
        animation: none !important;
        clip-path: none !important;
    }
    
    /* Disable cursor blink */
    .cursor,
    .hover-cursor,
    .typing-cursor {
        animation: none !important;
        opacity: 1 !important;
    }
    
    /* Instant transitions */
    .boot-container,
    .terminal-interface,
    .terminal-block,
    .log-line {
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-bg: #000000;
        --color-fg: #FFFFFF;
        --color-mid: #CCCCCC;
    }
    
    .terminal-block {
        border-width: 2px;
    }
}

/* Print styles */
@media print {
    /* Hide boot sequence and show terminal content */
    #boot-sequence {
        display: none !important;
    }
    
    #terminal-interface {
        display: block !important;
        opacity: 1 !important;
    }
    
    /* Remove animations */
    * {
        animation: none !important;
        transition: none !important;
    }
    
    /* Ensure readable text */
    body {
        background: white;
        color: black;
    }
    
    .terminal-block {
        page-break-inside: avoid;
        border: 1px solid black;
        margin-bottom: 20px;
    }
}

/* JavaScript disabled fallback */
.no-js #boot-sequence {
    display: none !important;
}

.no-js #terminal-interface {
    display: grid !important;
    opacity: 1 !important;
}

/* Audio not supported indicator (optional) */
.audio-not-supported-notice {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--color-mid, #808080);
    color: var(--color-fg, #E0E0E0);
    font-family: var(--font-body, monospace);
    font-size: 11px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
}

.audio-not-supported-notice.show {
    display: block;
    opacity: 1;
}

/* Fallback for CSS Grid not supported */
@supports not (display: grid) {
    .terminal-interface {
        display: block !important;
    }
    
    .terminal-block {
        width: 100%;
        margin-bottom: 2px;
    }
}

/* Fallback for CSS custom properties not supported */
@supports not (--css: variables) {
    :root {
        background: #000000;
        color: #E0E0E0;
    }
    
    body {
        font-family: 'Courier New', monospace;
    }
    
    .terminal-block {
        border: 1px solid #E0E0E0;
        padding: 16px;
    }
}

/* Connection error state */
.connection-error {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 30px;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid var(--color-fg, #E0E0E0);
    color: var(--color-fg, #E0E0E0);
    font-family: var(--font-body, monospace);
    text-align: center;
    z-index: 10000;
}

.connection-error.show {
    display: block;
}

.connection-error h2 {
    margin: 0 0 15px 0;
    font-size: 18px;
    letter-spacing: 2px;
}

.connection-error p {
    margin: 10px 0;
    font-size: 13px;
}

/* Skeleton loading states */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 25%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Disable skeleton animation with reduced motion */
@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: rgba(255, 255, 255, 0.05);
    }
}
