/* ===== COMPREHENSIVE GRAPHICS ERROR FIXES ===== */
/* Include this file alongside styles.css and media-quarys.css */

/* ===== IMAGE & MEDIA OPTIMIZATION ===== */

/* Fix all images to prevent distortion */
img,
picture {
    display: block;
    max-width: 100%;
    height: auto;
    width: 100%;
}

/* Prevent images from causing horizontal overflow */
img[src],
picture > source {
    width: auto;
    max-width: 100%;
    height: auto;
}

/* Profile Avatar Special Constraints */
.profile-avatar {
    max-width: 40px !important;
    max-height: 40px !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    object-fit: cover !important;
    object-position: center !important;
}

.profile-link {
    max-width: 40px !important;
    max-height: 40px !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    flex-shrink: 0 !important;
}

/* Video responsive sizing */
video,
iframe {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

/* SVG responsive sizing */
svg {
    display: block;
    max-width: 100%;
    height: auto;
    width: 100%;
}

/* ===== BACKGROUND IMAGE FIXES ===== */

/* Fix hero background for mobile devices */
.hero {
    background-size: cover;
    background-position: center;
    background-attachment: scroll;
    
    /* Prevent image from stretching on mobile */
    -webkit-background-size: cover;
    -o-background-size: cover;
    -moz-background-size: cover;
}

/* iOS Safari background image fix */
@supports (-webkit-touch-callout: none) {
    .hero {
        background-attachment: scroll !important;
        -webkit-background-attachment: scroll !important;
    }
}

/* ===== CONTAINER OVERFLOW FIXES ===== */

/* Prevent all containers from causing horizontal scroll */
body,
html,
main,
.container,
.main-content,
.hero,
.live-section,
.vote-section,
.betting-grid {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Fix nested container widths */
div {
    max-width: 100%;
    box-sizing: border-box;
}

/* ===== TEXT & TYPOGRAPHY FIXES ===== */

/* Prevent text overflow on mobile */
h1, h2, h3, h4, h5, h6,
p, span, a, button {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Fix long text in buttons */
.nav-btn,
.bet-button,
.odd,
button {
    word-break: break-word;
    white-space: normal;
}

/* ===== FORM ELEMENT FIXES ===== */

/* Ensure form inputs are not too large on mobile */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px; /* Prevent zoom on iOS */
    border-radius: 8px;
}

/* Fix mobile Safari input zoom issue */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select {
    font-size: 16px !important;
}

/* ===== FLEX & GRID OVERFLOW FIXES ===== */

/* Fix flex containers from causing overflow */
.nav,
.nav-right,
.betting-grid,
.teams-section,
#betForm {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

/* Prevent grid items from overflowing */
.betting-grid > *,
.teams-section > *,
.live-section > * {
    min-width: 0;
    max-width: 100%;
}

/* ===== SHADOW & BORDER FIXES ===== */

/* Prevent box-shadows from causing layout issues */
* {
    box-shadow: 0 0 0 transparent;
}

/* Re-apply shadows safely */
.nav {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.live-card,
.betting-card,
.team-card,
.vote-section {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease;
}

/* ===== PERFORMANCE OPTIMIZATION ===== */

/* Enable GPU acceleration for smooth animations */
.live-card,
.betting-card,
.team-card,
.nav-btn,
.bet-button {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Optimize animations */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== PRINT FIXES ===== */

/* Better print styling */
@media print {
    html,
    body {
        background: white;
        color: black;
        overflow: visible;
    }

    img {
        page-break-inside: avoid;
        max-width: 100% !important;
    }

    .no-print {
        display: none !important;
    }
}

/* ===== SMALL SCREEN CRITICAL FIXES ===== */

@media (max-width: 480px) {
    /* Stack layouts to prevent overflow */
    .betting-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .teams-section {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Ensure buttons don't overflow */
    .nav-btn,
    .bet-button {
        max-width: calc(100% - 1rem);
        margin: 0.25rem auto;
    }

    /* Fix modal/dialog widths */
    .modal,
    .matchup-dropdown,
    dialog {
        max-width: calc(100% - 2rem) !important;
        width: 100% !important;
    }

    /* Prevent large elements from overflowing */
    .hero p {
        max-width: 95vw !important;
        padding: 1rem !important;
    }

    /* Table horizontal scroll */
    table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
        width: 100%;
    }
}

/* ===== WEBKIT-SPECIFIC FIXES ===== */

/* iOS Safari fixes */
input,
select,
textarea {
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -webkit-appearance: none;
    appearance: none;
}

/* Remove default iOS styles */
button,
input[type="button"],
input[type="submit"] {
    -webkit-appearance: none;
    appearance: none;
    background-image: none;
    -webkit-background-clip: padding-box;
    background-clip: padding-box;
}

/* Fix viewport height issues on mobile */
html,
body {
    height: 100%;
}

/* ===== DARK MODE GRAPHICS FIXES ===== */

body.dark-mode img {
    opacity: 0.95;
}

body.dark-mode .hero {
    background-color: #1a1a1a;
}

/* ===== HIGH DPI DISPLAY OPTIMIZATION ===== */

@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    /* Use higher resolution images if available */
    img {
        image-rendering: -webkit-optimize-contrast;
    }

    /* Crisp rendering for lines */
    border,
    box-shadow {
        image-rendering: auto;
    }
}

/* ===== FINAL SAFETY NET ===== */

/* Absolute last resort for overflow issues */
* {
    max-width: 100%;
}

body * {
    box-sizing: border-box;
}
