* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Skip navigation link - visually hidden until focused */
.skip-link {
    position: absolute;
    top: -44px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px 16px;
    z-index: 9999;
    border-radius: 0 0 6px 0;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid white;
    outline-offset: 2px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    padding-bottom: 0;
    color: #333;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    flex: 1;
}

header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header h2 {
    font-size: 1.2em;
    font-weight: 300;
    opacity: 0.9;
}

.controls {
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-wrap: wrap;
    gap: 10px;
}

.sort-help {
    color: #6c757d;
    font-size: 12px;
}

.btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s;
    touch-action: manipulation; /* Prevent double-tap zoom */
    min-height: 44px; /* iOS recommended touch target */
}

.btn:hover {
    background: #5568d3;
}

.btn:active {
    transform: scale(0.98);
}

/* Focus-visible outlines for keyboard navigation */
.btn:focus-visible,
.tab-btn:focus-visible,
.detail-close:focus-visible,
.footer-link:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.standings-table th:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: -2px;
}

.last-updated {
    color: #6c757d;
    font-size: 14px;
}

.loading, .error {
    padding: 30px;
    text-align: center;
    font-size: 18px;
}

.loading {
    color: #667eea;
}

#loading {
    position: relative;
    z-index: 1;
}

.error {
    color: #dc3545;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    margin: 20px;
}

.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 300px); /* Adjust based on header/controls height */
    padding: 20px;
    position: relative;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.standings-table thead {
    background: #f8f9fa;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.standings-table th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation; /* Prevent double-tap zoom */
    min-height: 44px; /* Better touch target */
}

.standings-table th:hover {
    background: #e9ecef;
}

.standings-table th.sorted {
    background: #667eea;
    color: white;
    position: relative;
    z-index: 11; /* Ensure sorted headers stay on top */
}

.standings-table th.sorted::after {
    content: attr(data-sort-indicator);
    font-size: 10px;
    margin-left: 4px;
    font-weight: bold;
}

/* Visual indicators for sort priority */
.standings-table th.sorted-1 {
    background: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
}

.standings-table th.sorted-2 {
    background: #5568d3;
    opacity: 0.9;
}

.standings-table th.sorted-3 {
    background: #4a5bc4;
    opacity: 0.8;
}

.standings-table th.sorted-4,
.standings-table th.sorted-5 {
    background: #3e4db5;
    opacity: 0.7;
}

.standings-table tbody tr {
    border-bottom: 1px solid #e9ecef;
    transition: background 0.2s;
}

.standings-table tbody tr:hover {
    background: #f8f9fa;
}

/* Double line below 8th row (Round of 16 qualification) */
.standings-table tbody tr.qualification-round-of-16 {
    border-bottom: 3px double #667eea;
}

/* Double line below 24th row (Knockout play-off qualification) */
.standings-table tbody tr.qualification-knockout {
    border-bottom: 3px double #764ba2;
}

.standings-table td {
    padding: 12px 8px;
    text-align: left;
}

.standings-table td:first-child {
    font-weight: 600;
    color: #667eea;
}

.standings-table td:nth-child(2) {
    font-weight: 600;
}

.team-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.team-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.team-logo-placeholder {
    width: 32px;
    height: 32px;
    display: inline-block;
    flex-shrink: 0;
}

.team-name {
    flex: 1;
    min-width: 0;
}

.team-cell.clickable,
.standings-table td.clickable {
    cursor: pointer;
    transition: background-color 0.2s;
}

.team-cell.clickable:hover,
.standings-table td.clickable:hover {
    background-color: #e9ecef;
}

/* Detail row styles */
.detail-row {
    background: #f8f9fa;
}

.detail-cell {
    padding: 0 !important;
    border-top: 2px solid #667eea;
}

.detail-panel {
    padding: 20px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 1000px;
    }
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #dee2e6;
}

.detail-team-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.detail-team-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.detail-header h3 {
    margin: 0;
    font-size: 1.5em;
    color: #333;
}

.detail-subtitle {
    margin: 5px 0 0 0;
    color: #6c757d;
    font-size: 0.9em;
}

.detail-subtitle strong {
    font-size: 1.2em;
}

.detail-subtitle strong.solkoff-value {
    color: #28a745;
}

.detail-subtitle strong.strength-value {
    color: #667eea;
}

.detail-close {
    background: #dc3545;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-close:hover {
    background: #c82333;
}

.detail-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}


.detail-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.detail-section h4 {
    margin: 0 0 15px 0;
    color: #667eea;
    font-size: 1.1em;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 10px;
}

.opponents-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.opponent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    transition: background 0.2s;
    flex-wrap: wrap;
}

.opponent-item:hover {
    background: #e9ecef;
}

.opponent-logo,
.opponent-logo-placeholder {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.opponent-logo-placeholder {
    display: inline-block;
}

.opponent-main-info {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.opponent-name {
    font-weight: 600;
    color: #333;
}

.opponent-stats {
    font-size: 0.85em;
    color: #6c757d;
}

.opponent-matches-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    min-width: 120px;
}

.match-results {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.match-result {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.match-result.match-win {
    background: #d4edda;
    color: #155724;
}

.match-result.match-draw {
    background: #fff3cd;
    color: #856404;
}

.match-result.match-loss {
    background: #f8d7da;
    color: #721c24;
}

.opponent-meta {
    display: flex;
    gap: 10px;
    align-items: center;
}

.opponent-points {
    font-weight: 600;
    color: #28a745;
    font-size: 0.9em;
}

.opponent-matches {
    color: #6c757d;
    font-size: 0.85em;
}

.no-opponents {
    color: #6c757d;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.calculation {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.calculation-item {
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

.calculation-label {
    font-weight: 600;
    color: #667eea;
    margin: 0 0 10px 0;
    font-size: 1em;
}

.calculation-formula {
    font-size: 1.3em;
    font-weight: 600;
    color: #333;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
}

.calculation-explanation {
    color: #6c757d;
    font-size: 0.9em;
    margin-top: 8px;
    font-style: italic;
}

.detail-loading,
.detail-error {
    padding: 40px;
    text-align: center;
    color: #6c757d;
}

.detail-error {
    color: #dc3545;
}

.standings-table td:nth-last-child(2) {
    font-weight: 600;
    color: #28a745;
}

.standings-table td.strength-score {
    font-weight: 600;
    color: #667eea;
    font-size: 1.05em;
}

/* Tab styles */
.tabs-container {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.tabs-header {
    display: flex;
    flex-direction: row;
    gap: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: none;
    overflow-x: auto;
    flex-wrap: nowrap;
    width: 100%;
    padding: 4px;
}

.tabs-header::-webkit-scrollbar {
    height: 6px;
}

.tabs-header::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.tabs-header::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.tabs-header::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.tab-btn {
    padding: 16px 28px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    transition: all 0.3s ease;
    white-space: nowrap;
    position: relative;
    margin: 2px;
    letter-spacing: 0.3px;
    min-height: 44px;
    touch-action: manipulation;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateY(-1px);
}

.tab-btn.active {
    background: white;
    color: #667eea;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid white;
}

.tabs-content {
    position: relative;
    padding: 20px;
    background: white;
    min-height: 400px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.tab-pane.active {
    display: block !important;
    visibility: visible !important;
}

.tabs-content {
    padding: 20px;
    background: white;
    min-height: 400px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.data-not-available {
    padding: 60px 30px;
    text-align: center;
    color: #6c757d;
    font-size: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 20px;
}

.data-not-available-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.data-not-available h3 {
    color: #495057;
    margin-bottom: 10px;
    margin-top: 0;
}

.data-not-available .info-note {
    margin-top: 15px;
    padding: 12px;
    background: #e7f3ff;
    border-left: 4px solid #667eea;
    border-radius: 4px;
    color: #495057;
    font-size: 14px;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 8px;
        margin-bottom: 10px;
    }

    header {
        padding: 20px 15px;
    }

    header h1 {
        font-size: 1.5em;
        margin-bottom: 8px;
    }

    header h2 {
        font-size: 1em;
    }

    .controls {
        padding: 15px;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .controls > * {
        width: 100%;
    }

    .btn {
        width: 100%;
        padding: 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .sort-help {
        text-align: center;
        font-size: 11px;
    }

    .table-container {
        padding: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-height: none;
    }

    .standings-table {
        font-size: 11px;
        min-width: 800px; /* Force horizontal scroll on very small screens */
    }

    .standings-table th,
    .standings-table td {
        padding: 8px 4px;
    }

    .standings-table th {
        font-size: 10px;
        white-space: nowrap;
    }

    /* Hide less important columns on mobile */
    .standings-table th:nth-child(4), /* W */
    .standings-table td:nth-child(4),
    .standings-table th:nth-child(5), /* D */
    .standings-table td:nth-child(5),
    .standings-table th:nth-child(6), /* L */
    .standings-table td:nth-child(6),
    .standings-table th:nth-child(8), /* GA */
    .standings-table td:nth-child(8) {
        display: none;
    }

    .team-logo {
        width: 24px;
        height: 24px;
    }

    .team-logo-placeholder {
        width: 24px;
        height: 24px;
    }

    .team-name {
        font-size: 12px;
    }

    .tabs-header {
        padding: 2px;
        gap: 2px;
    }

    .tab-btn {
        padding: 12px 16px;
        font-size: 13px;
        white-space: nowrap;
    }

    .tabs-content {
        padding: 15px 10px;
        min-height: 300px;
    }

    .detail-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .detail-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .detail-team-info {
        width: 100%;
    }

    .detail-close {
        align-self: flex-end;
    }

    .detail-panel {
        padding: 15px;
    }

    .detail-section {
        padding: 15px;
    }

    .opponent-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .opponent-matches-info {
        width: 100%;
        align-items: flex-start;
    }

    .match-results {
        justify-content: flex-start;
    }

    .last-updated {
        text-align: center;
        font-size: 12px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    header h1 {
        font-size: 2em;
    }

    .controls {
        padding: 15px 20px;
    }

    .detail-content {
        gap: 20px;
    }

    .tab-btn {
        padding: 14px 20px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    header {
        padding: 15px 10px;
    }

    header h1 {
        font-size: 1.3em;
    }

    header h2 {
        font-size: 0.9em;
    }

    .controls {
        padding: 12px;
    }

    .table-container {
        padding: 5px;
        max-height: none;
    }

    .standings-table {
        font-size: 10px;
        min-width: 700px;
    }

    .standings-table th,
    .standings-table td {
        padding: 6px 3px;
    }

    /* Hide even more columns on very small screens */
    .standings-table th:nth-child(7), /* GF */
    .standings-table td:nth-child(7),
    .standings-table th:nth-child(9), /* GD */
    .standings-table td:nth-child(9) {
        display: none;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 12px;
    }

    .tabs-content {
        padding: 10px 5px;
    }
}

/* Footer styles */
.page-footer {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 20px;
    text-align: center;
    margin-top: auto;
    border-radius: 12px 12px 0 0;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.footer-text {
    margin: 0;
    font-size: 0.95em;
    opacity: 0.9;
}

.footer-text strong {
    font-weight: 600;
}

.footer-links {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    text-decoration: none;
    font-size: 0.9em;
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.footer-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.footer-link svg {
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .footer-content {
        gap: 12px;
    }
    
    .footer-links {
        gap: 12px;
    }
    
    .footer-link {
        padding: 6px 12px;
        font-size: 0.85em;
    }
    
    .footer-link svg {
        width: 18px;
        height: 18px;
    }
}

