/* ===== RESPONSIVE DESIGN SYSTEM ===== */

/* Mobile-First Approach */
/* Base styles are mobile-first, then enhanced for larger screens */

/* ===== EXTRA SMALL DEVICES (phones, less than 576px) ===== */
@media (max-width: 575.98px) {
    /* Typography */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
    
    .hero-title { font-size: 1.8rem; }
    .section-title { font-size: 1.75rem; }
    .section-description { font-size: 0.95rem; }
    
    /* Layout */
    .container {
        padding: 0 var(--spacing-sm);
    }
    
    /* Buttons */
    .btn {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.85rem;
        width: 100%;
        justify-content: center;
    }
    
    .btn-lg {
        padding: var(--spacing-md) var(--spacing-lg);
        font-size: 0.9rem;
    }
    
    /* Cards */
    .card,
    .team-card,
    .player-card,
    .match-card {
        margin-bottom: var(--spacing-lg);
        padding: var(--spacing-md);
    }
    
    /* Navigation */
    .nav-buttons {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .nav-btn {
        width: 100%;
        padding: var(--spacing-md);
        font-size: 0.9rem;
    }
    
    /* Forms */
    .form-row {
        flex-direction: column;
    }
    
    .form-group {
        margin-bottom: var(--spacing-md);
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: var(--spacing-md);
    }
    
    /* Tables */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        font-size: 0.8rem;
        min-width: 600px;
    }
    
    th, td {
        padding: var(--spacing-xs) 4px;
        white-space: nowrap;
    }
    
    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none;
    }
    
    /* Modals */
    .modal,
    .team-modal,
    .player-modal {
        margin: 10px;
        max-height: 95vh;
    }
    
    .modal-header {
        padding: var(--spacing-md);
        flex-direction: column;
        gap: var(--spacing-sm);
        text-align: center;
    }
    
    .modal-body {
        padding: var(--spacing-md);
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
    
    .stat-item {
        flex-direction: column;
        text-align: center;
        padding: var(--spacing-md);
    }
    
    /* Footer */
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .footer-links {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }
}

/* ===== SMALL DEVICES (landscape phones, 576px and up) ===== */
@media (min-width: 576px) and (max-width: 767.98px) {
    /* Typography */
    h1 { font-size: 2rem; }
    h2 { font-size: 1.75rem; }
    .hero-title { font-size: 2.2rem; }
    .section-title { font-size: 2rem; }
    
    /* Layout */
    .container {
        max-width: 540px;
        padding: 0 var(--spacing-md);
    }
    
    /* Grid adjustments */
    .matches-grid,
    .players-grid {
        grid-template-columns: 1fr;
    }
    
    .teams-carousel .swiper-slide {
        width: 100%;
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Footer */
    .footer-links {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .footer-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== MEDIUM DEVICES (tablets, 768px and up) ===== */
@media (min-width: 768px) and (max-width: 991.98px) {
    /* Typography */
    h1 { font-size: 2.5rem; }
    h2 { font-size: 2rem; }
    .hero-title { font-size: 2.8rem; }
    .section-title { font-size: 2.5rem; }
    
    /* Layout */
    .container {
        max-width: 720px;
    }
    
    /* Grid adjustments */
    .matches-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .players-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .teams-carousel .swiper {
        padding: 0 50px; /* Space for navigation arrows */
    }
    
    /* Navigation */
    .nav-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .nav-btn {
        flex: 1;
        min-width: 140px;
        max-width: 200px;
    }
    
    /* Forms */
    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-lg);
    }
    
    /* Tables */
    table {
        font-size: 0.9rem;
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Footer */
    .footer-links {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .footer-stats {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Modal adjustments */
    .modal {
        max-width: 600px;
    }
}

/* ===== LARGE DEVICES (desktops, 992px and up) ===== */
@media (min-width: 992px) and (max-width: 1199.98px) {
    /* Typography */
    h1 { font-size: 3rem; }
    h2 { font-size: 2.5rem; }
    .hero-title { font-size: 3.2rem; }
    .section-title { font-size: 2.8rem; }
    
    /* Layout */
    .container {
        max-width: 960px;
    }
    
    /* Grid adjustments */
    .matches-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .players-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .teams-carousel .swiper-slide {
        width: calc(50% - 15px);
    }
    
    /* Navigation */
    .nav-buttons {
        justify-content: center;
        flex-wrap: nowrap;
    }
    
    .nav-btn {
        flex: none;
        min-width: 160px;
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    /* Tables - show more columns */
    .hide-tablet {
        display: table-cell;
    }
    
    /* Modal adjustments */
    .modal {
        max-width: 800px;
    }
}

/* ===== EXTRA LARGE DEVICES (large desktops, 1200px and up) ===== */
@media (min-width: 1200px) {
    /* Typography */
    h1 { font-size: 3.5rem; }
    h2 { font-size: 3rem; }
    .hero-title { font-size: 4rem; }
    .section-title { font-size: 3rem; }
    
    /* Layout */
    .container {
        max-width: 1140px;
    }
    
    /* Grid adjustments */
    .matches-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .players-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .teams-carousel .swiper-slide {
        width: calc(33.333% - 20px);
    }
    
    /* Stats */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Tables - show all columns */
    .hide-desktop {
        display: table-cell;
    }
    
    /* Modal adjustments */
    .modal {
        max-width: 900px;
    }
}

/* ===== ULTRA-WIDE SCREENS (1400px and up) ===== */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }
    
    .hero-title {
        font-size: 4.5rem;
    }
    
    .teams-carousel .swiper-slide {
        width: calc(25% - 22.5px);
    }
    
    .matches-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .players-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    .nav-btn,
    .tab-btn {
        min-height: 48px;
    }
    
    /* Remove hover effects on touch devices */
    .hover-lift:hover,
    .hover-scale:hover,
    .team-card:hover,
    .player-card:hover,
    .match-card:hover {
        transform: none;
        box-shadow: var(--shadow-lg);
    }
    
    /* Simplify complex hover interactions */
    .team-tooltip,
    .tooltip-text {
        display: none;
    }
    
    /* Optimize scrolling */
    .table-container,
    .teams-scroll {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (orientation: landscape) and (max-height: 600px) {
    /* Reduce hero section height on landscape phones */
    .hero-section {
        min-height: 80vh;
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    /* Compact navigation */
    .main-header {
        padding: 10px 0;
    }
    
    .navbar-brand .brand-title {
        font-size: 1.2rem;
    }
    
    /* Reduce section padding */
    section {
        padding: var(--spacing-xl) 0;
    }
}

/* ===== HIGH-DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure images are crisp on retina displays */
    .team-logo,
    .team-logo-small,
    .team-logo-large,
    .conference-logo,
    .main-logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== REDUCED DATA MODE ===== */
@media (prefers-reduced-data: reduce) {
    /* Disable background images and effects */
    .hero-background,
    .stats-bar::before,
    .main-footer::before {
        background-image: none;
    }
    
    /* Simplify animations */
    .loading-spinner,
    .sparkle,
    .teams-scroll {
        animation: none;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --white: #1a1a1a;
        --gray-100: #2d2d2d;
        --gray-200: #3d3d3d;
        --gray-300: #4d4d4d;
        --gray-400: #5d5d5d;
        --gray-500: #6d6d6d;
        --gray-600: #8d8d8d;
        --gray-700: #adadad;
        --gray-800: #cdcdcd;
        --gray-900: #ffffff;
    }
    
    body {
        background-color: var(--white);
        color: var(--gray-900);
    }
    
    .team-card,
    .player-card,
    .match-card,
    .contact-form-container {
        background: var(--gray-100);
        border-color: var(--gray-300);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    /* Reset colors for print */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    /* Hide interactive elements */
    .nav-buttons,
    .btn,
    .back-to-top,
    .mobile-menu-toggle,
    .scroll-indicator {
        display: none !important;
    }
    
    /* Optimize layout for print */
    .container {
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Ensure proper page breaks */
    .section {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    .team-card,
    .player-card,
    .match-card {
        page-break-inside: avoid;
        break-inside: avoid;
        border: 1px solid #000 !important;
        margin-bottom: 1rem !important;
    }
    
    /* Typography for print */
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        break-after: avoid;
    }
    
    /* Show URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
    
    /* Hide decorative elements */
    .section-badge,
    .sparkle,
    .loading-spinner {
        display: none !important;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus indicators */
@media (prefers-reduced-motion: no-preference) {
    .btn:focus,
    .nav-btn:focus,
    .tab-btn:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid var(--primary-wine);
        outline-offset: 2px;
        animation: focusPulse 0.3s ease;
    }
}

@keyframes focusPulse {
    0% { box-shadow: 0 0 0 0 rgba(139, 21, 56, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(139, 21, 56, 0); }
    100% { box-shadow: 0 0 0 0 rgba(139, 21, 56, 0); }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    .btn,
    .nav-btn,
    .tab-btn {
        border: 2px solid currentColor;
    }
    
    .team-card,
    .player-card,
    .match-card {
        border: 2px solid var(--gray-900);
    }
    
    .badge {
        border: 1px solid currentColor;
    }
}

/* ===== DEVICE-SPECIFIC OPTIMIZATIONS ===== */

/* iPhone specific optimizations */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari safe area handling */
    .main-header {
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .main-footer {
        padding-bottom: max(var(--spacing-xl), env(safe-area-inset-bottom));
    }
    
    /* Prevent zoom on input focus */
    input, select, textarea {
        font-size: 16px;
    }
    
    /* Smooth scrolling optimization */
    .table-container,
    .teams-scroll {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Android specific optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android Chrome optimizations */
    .btn,
    .nav-btn {
        -webkit-tap-highlight-color: rgba(139, 21, 56, 0.2);
    }
    
    /* Optimize touch interactions */
    .team-card,
    .player-card,
    .match-card {
        touch-action: manipulation;
    }
}

/* ===== RESPONSIVE IMAGES ===== */
.team-logo,
.team-logo-small,
.team-logo-large,
.conference-logo,
.main-logo {
    max-width: 100%;
    height: auto;
}

/* Responsive image sizing */
@media (max-width: 576px) {
    .team-logo-large {
        width: 60px;
        height: 60px;
    }
    
    .team-logo {
        width: 40px;
        height: 40px;
    }
    
    .team-logo-small {
        width: 25px;
        height: 25px;
    }
}

@media (min-width: 577px) and (max-width: 768px) {
    .team-logo-large {
        width: 70px;
        height: 70px;
    }
    
    .team-logo {
        width: 50px;
        height: 50px;
    }
    
    .team-logo-small {
        width: 30px;
        height: 30px;
    }
}

/* ===== RESPONSIVE TYPOGRAPHY SCALE ===== */
@media (max-width: 576px) {
    .lead { font-size: 1rem; }
    .small { font-size: 0.8rem; }
}

@media (min-width: 577px) and (max-width: 768px) {
    .lead { font-size: 1.1rem; }
    .small { font-size: 0.85rem; }
}

@media (min-width: 769px) {
    .lead { font-size: 1.25rem; }
    .small { font-size: 0.875rem; }
}

/* ===== RESPONSIVE SPACING ===== */
@media (max-width: 576px) {
    section {
        padding: var(--spacing-xl) 0;
    }
    
    .hero-section {
        padding: var(--spacing-2xl) 0;
    }
    
    .card,
    .team-card,
    .player-card,
    .match-card {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-md);
    }
}

@media (min-width: 577px) and (max-width: 992px) {
    section {
        padding: var(--spacing-2xl) 0;
    }
    
    .hero-section {
        padding: var(--spacing-3xl) 0;
    }
    
    .card,
    .team-card,
    .player-card,
    .match-card {
        padding: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
    }
}

@media (min-width: 993px) {
    section {
        padding: var(--spacing-3xl) 0;
    }
    
    .hero-section {
        padding: var(--spacing-3xl) 0;
        min-height: 100vh;
    }
    
    .card,
    .team-card,
    .player-card,
    .match-card {
        padding: var(--spacing-xl);
        margin-bottom: var(--spacing-xl);
    }
}

/* ===== RESPONSIVE UTILITIES ===== */

/* Visibility utilities */
.d-mobile-none { display: none; }
.d-tablet-none { display: block; }
.d-desktop-none { display: block; }

@media (min-width: 768px) {
    .d-mobile-none { display: block; }
    .d-tablet-none { display: none; }
}

@media (min-width: 992px) {
    .d-tablet-none { display: block; }
    .d-desktop-none { display: none; }
}

/* Text alignment utilities */
.text-mobile-center { text-align: center; }
.text-tablet-left { text-align: center; }
.text-desktop-left { text-align: center; }

@media (min-width: 768px) {
    .text-mobile-center { text-align: left; }
    .text-tablet-left { text-align: left; }
}

@media (min-width: 992px) {
    .text-desktop-left { text-align: left; }
}

/* Responsive flex utilities */
.flex-mobile-column {
    flex-direction: column;
}

@media (min-width: 768px) {
    .flex-tablet-row {
        flex-direction: row;
    }
}

@media (min-width: 992px) {
    .flex-desktop-row {
        flex-direction: row;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Optimize animations for lower-end devices */
@media (max-width: 576px) {
    .teams-scroll {
        animation-duration: 40s; /* Slower animation on mobile */
    }
    
    .loading-spinner {
        animation-duration: 1.5s; /* Slower spinner */
    }
    
    /* Disable complex hover effects on mobile */
    .hover-lift,
    .hover-scale,
    .hover-glow {
        transition: none;
    }
    
    .hover-lift:hover,
    .hover-scale:hover,
    .hover-glow:hover {
        transform: none;
    }
}

/* ===== FALLBACKS FOR OLDER BROWSERS ===== */

/* CSS Grid fallback */
@supports not (display: grid) {
    .stats-grid,
    .matches-grid,
    .players-grid,
    .footer-links {
        display: flex;
        flex-wrap: wrap;
    }
    
    .stats-grid > *,
    .matches-grid > *,
    .players-grid > *,
    .footer-links > * {
        flex: 1;
        min-width: 250px;
        margin: var(--spacing-sm);
    }
}

/* Flexbox fallback */
@supports not (display: flex) {
    .nav-buttons,
    .hero-actions,
    .contact-content {
        display: block;
    }
    
    .nav-btn,
    .btn {
        display: inline-block;
        margin: var(--spacing-sm);
    }
}

/* CSS Variables fallback */
@supports not (color: var(--primary-wine)) {
    .root {
        /* Fallback colors */
    }
    
    .btn-primary {
        background: #8B1538;
        color: #FFFFFF;
    }
    
    .section-title {
        color: #2C3E50;
    }
}

/* ===== LOADING STATES ===== */
@media (max-width: 768px) {
    .loading-state {
        padding: var(--spacing-xl) var(--spacing-md);
    }
    
    .loading-spinner {
        width: 30px;
        height: 30px;
        border-width: 3px;
    }
    
    .loading-text {
        font-size: 0.9rem;
    }
}

/* ===== FINAL RESPONSIVE CHECKS ===== */

/* Ensure minimum touch target sizes */
@media (pointer: coarse) {
    .btn,
    .nav-btn,
    .tab-btn,
    .social-link,
    .mobile-menu-toggle {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Ensure readable line lengths */
@media (min-width: 1200px) {
    .section-description,
    .hero-subtitle,
    p {
        max-width: 65ch;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Optimize for very small screens */
@media (max-width: 320px) {
    .container {
        padding: 0 var(--spacing-xs);
    }
    
    .btn {
        font-size: 0.8rem;
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .hero-title {
        font-size: 1.5rem;
    }
    
    .section-title {
        font-size: 1.4rem;
    }
}