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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 30px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

select, button {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 8px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

button {
    background: #667eea;
    color: white;
}

button:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

select:hover {
    border-color: #5568d3;
}

.phase-title {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 10px;
    margin: 30px 0 20px 0;
    font-size: 1.5em;
    font-weight: bold;
    text-align: center;
}

.matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

/* Estilos específicos para centrar SOLO las semifinales */
.semifinals-grid {
    /* Centrar las tarjetas dentro del grid (útil cuando hay 1 o 2 tarjetas como en semifinales) */
    justify-content: center;
    justify-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.match-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s;
    /* Asegurar ancho máximo para que las tarjetas no se estiren demasiado al centrarse */
    max-width: 420px;
    width: 100%;
}

.match-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.match-number {
    font-size: 12px;
    color: #666;
    font-weight: bold;
    margin-bottom: 10px;
}

.match-players {
    display: flex;
    /* Comportamiento por defecto: espacio entre jugadores */
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
}

/* Cuando la grid sea la de semifinales, queremos centrar los jugadores dentro de cada tarjeta */
.semifinals-grid .match-players {
    justify-content: center;
    gap: 10px;
}

.player {
    flex: 0 0 auto;
    text-align: center;
    font-weight: bold;
    font-size: 18px;
    min-width: 110px;
}

.player.blue {
    color: #2196F3;
}

.player.red {
    color: #f44336;
}

.vs {
    padding: 0 15px;
    color: #666;
    font-weight: bold;
}

.score {
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    margin: 10px 0;
}

.winner-badge {
    background: gold;
    color: #333;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    margin-top: 10px;
}

.standings {
    background: white;
    border-radius: 12px;
    /* Permitir scroll horizontal en móviles para que las tablas no se salgan de la pantalla */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* suaviza el scroll en iOS */
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    /* Quitamos el padding del contenedor principal para evitar gaps a la derecha
       (moved padding inside .standings-inner) */
    padding: 0;
}

/* Permitir que los contenedores de tablas se encojan correctamente dentro de grid */
.standings {
    min-width: 0; /* esencial para que el grid pueda contraer las columnas y el overflow funcione */
    width: 100%;
}

/* Contenedor para las tablas de grupos (2 o más tablas) */
.group-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: stretch; /* asegurar que las tarjetas tengan la misma altura y estiren correctamente */
}

/* En pantallas pequeñas, apilar las tablas para evitar overflow horizontal combinado */
@media (max-width: 900px) {
    .group-tables {
        grid-template-columns: 1fr;
    }
}

.standings-inner {
    /* Comportamiento por defecto: ocupar 100% del ancho del contenedor para tablas
       standalone (ej. la tabla de CLASIFICADOS). */
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    vertical-align: top;
    position: relative;
    overflow: visible;
    padding: 6px;
}

/* Para tablas dentro de .group-tables (varias tarjetas lado a lado) queremos
   que el wrapper se ajuste al ancho de la tabla desplazable; aplicamos ahí
   width: max-content para que la franja azul acompañe correctamente al deslizar. */
.group-tables .standings-inner {
    display: block;
    width: max-content;
    min-width: 0;
    box-sizing: border-box;
    vertical-align: top;
    position: relative;
    overflow: visible;
    padding: 6px;
}

.standings table {
    /* Por defecto las tablas standalone ocupan todo el ancho del contenedor */
    width: 100%;
    border-collapse: collapse;
    min-width: 520px; /* fallback razonable */
}

/* Para las tablas dentro de .group-tables (grupos A/B/C) dejamos que la tabla quede
   con su ancho natural y el wrapper controle el scroll horizontal. */
.group-tables .standings table {
    width: auto;
    border-collapse: collapse;
    min-width: 640px;
}

/* Título del bloque de standings: lo estilamos para que se vea como un header sólido
   y que no deje franjas blancas cuando el contenido se desplaza. */
.standings-title {
    text-align: center;
    padding: 10px 12px;
    color: white;
    margin: 0;
    /* Hacemos el fondo transparente: el pseudo ::before en .standings-inner
       provee el fondo azul para evitar duplicados. */
    background: transparent;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    /* Hacemos que el título se comporte como bloque de ancho completo dentro de .standings-inner */
    display: block;
}

/* Para que no se vea la franja blanca al desplazarse, el fondo del contenedor .standings
   seguirá siendo blanco; sin embargo el header está dentro de .standings-inner que se desplaza
   junto con la tabla. */
.standings {
    /* padding movido a .standings-inner para evitar gaps visuales a la derecha */
    padding: 0;
}

.standings-inner h4.standings-title {
    /* extender ligeramente el ancho para cubrir el borde redondeado del cuadro */
    padding-left: 16px;
    padding-right: 16px;
}

/* Si por algún motivo hay tablas sin .standings-inner, queremos que su <th>
   tengan el fondo azul — por eso detectamos el caso donde no existe .standings-inner
   (usando la regla general .standings th ya es transparente). Para mantener compatibilidad,
   si detectás problemas en páginas antiguas, hace un hard refresh (Ctrl+F5). */

/* .phase-title + .standings th {
    background: transparent;
    color: #333; /* mantengo texto oscuro cuando el header principal arriba ya es azul
} */

.standings > table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: left;
    font-weight: bold;
}
.standings > table td {
    color: #333;
    padding: 12px 15px;
}

/* Tablas envueltas por .standings-inner (tienen el header azul representado por ::before)
   — las <th> deben ser transparentes y el texto blanco para legibilidad. */
.standings .standings-inner table th {
    /* No transparentes: queremos que el recuadro azul se muestre sólido y acompañe
       el desplazamiento horizontal; el texto será blanco para contraste. */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    padding: 15px;
    text-align: left;
    font-weight: bold;
}
.standings .standings-inner table td {
    color: #333;
    padding: 12px 15px;
}

.standings td {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}

.standings tr:hover {
    background: #f5f7fa;
}

/* REGLAS FINALES DE CONTRASTE: asegurar que texto siempre sea legible */
.standings table th {
    /* si por cualquier razón quedó transparente, forzamos texto blanco sobre azul */
    color: #fff !important;
}
.standings > table td,
.standings .standings-inner table td,
.standings table td {
    color: #222 !important;
}
/* Asegurar que los elementos <strong> no cambien el color y hereden el color del td/th */
.standings td strong,
.standings th strong {
    color: inherit !important;
}

.position {
    font-weight: bold;
    color: #667eea;
    font-size: 18px;
}

.podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 20px;
    margin: 40px 0;
    padding: 20px;
}

.podium-place {
    text-align: center;
    padding: 30px 40px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    transition: transform 0.3s;
}

.podium-place:hover {
    transform: translateY(-10px);
}

.podium-place.first {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    order: 2;
    font-size: 1.3em;
}

.podium-place.second {
    background: linear-gradient(135deg, #C0C0C0 0%, #808080 100%);
    order: 1;
    font-size: 1.1em;
}

.podium-place.third {
    background: linear-gradient(135deg, #CD7F32 0%, #8B4513 100%);
    order: 3;
    font-size: 1.1em;
}

.medal {
    font-size: 3em;
    margin-bottom: 10px;
}

.place-name {
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin-bottom: 5px;
}

.place-player {
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
}

.playoff-bracket {
    display: flex;
    flex-direction: column;
    gap: 30px;
    margin: 20px 0;
}

.bracket-round {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 20px;
}

@media (max-width: 768px) {
    .matches-grid {
        grid-template-columns: 1fr;
    }

    .podium {
        flex-direction: column;
        align-items: center;
    }

    .podium-place {
        width: 80%;
    }
}

/* Ajustes adicionales para pantallas muy pequeñas */
@media (max-width: 480px) {
    .standings th, .standings td {
        padding: 10px;
        font-size: 14px;
    }

    /* Relajar el min-width en móviles muy angostos para que el scroll sea menor */
    .standings table {
        min-width: 420px;
    }

    /* Ajustes menores de tarjetas y textos para móviles */
    .match-card {
        padding: 16px;
    }

    h1 {
        font-size: 1.8em;
    }
}

/* Si la .standings viene justo después de una .phase-title, ocultamos la franja
   azul interna para evitar duplicados. */
.phase-title + .standings .standings-inner::before {
    display: none;
}

/* Cuando ocultamos la franja interna (.standings-inner::before) porque arriba ya hay una
   .phase-title azul, debemos asegurarnos que las cabeceras <th> dentro de esa tabla
   sean oscuras para ser legibles sobre el fondo blanco. */
.phase-title + .standings .standings-inner table th {
    color: #333 !important;
    background: transparent !important;
}

/* Para las tablas dentro de .group-tables (ej. formatos 8,9,10) usamos un enfoque
   más simple: ocultamos el ::before y damos background azul a las <th> directamente,
   así evitamos transparencias y mantenemos la apariencia al scrollear. */
.group-tables .standings-inner::before {
    display: block; /* reactivar la franja azul redondeada */
}
.group-tables .standings .standings-inner table th,
.group-tables .standings > table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

/* Asegurar comportamiento correcto para tablas standalone dentro de #resultado
    (ej. '✅ CLASIFICADOS A PLAYOFFS') */
#resultado > .standings {
    width: 100%;
    margin: 30px 0; /* centrar y dar espacio vertical */
}
#resultado > .standings > table {
    width: 100%;
    min-width: 0; /* permitir que ocupe todo el ancho sin dejar espacios en blanco */
}
