* {
    font-family: sans-serif;
    box-sizing: border-box;
}

body {
    background: #cff;
    transition: background 0.5s;
    margin: 0;
    padding: 10px 10px 60px;
    color: #212529;
}

.logged body {
    background: #b2f2bb;
}

h1,
h2,
h3 {
    margin-top: 0;
    text-align: center;
}

b,
strong {
    font-weight: bold;
}

a {
    color: #1971c2;
}

.wrap {
    max-width: 760px;
    margin: 0 auto;
}

/* marquee retro (igual que timba) */
marquee {
    background: #ffd700;
    color: #000000;
    border: 6px dotted #e67e22;
    box-shadow:
        0 0 20px rgba(255, 215, 0, 0.8),
        inset 0 0 10px rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    font-size: 18px;
    text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.8);
    padding: 10px;
    margin-bottom: 14px;
}

.secret-admin-title {
    cursor: help;
    user-select: none;
}

/* ---- estados loading / anon / logged ---- */
.if-anon,
.if-logged {
    display: none;
}

.anon .if-anon {
    display: block;
}

.logged .if-logged {
    display: block;
}

.loading .if-anon,
.loading .if-logged {
    display: none;
}

#loading-msg {
    display: none;
    text-align: center;
    font-style: italic;
    margin: 40px 0;
}

.loading #loading-msg {
    display: block;
}

/* ---- cards (timba) ---- */
.card {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.me-card {
    background: #212529;
    color: #b2f2bb;
}

.me-card .stat {
    display: inline-block;
    margin: 0 14px;
    text-align: center;
}

.me-card .stat .num {
    font-size: 28px;
    font-weight: bold;
    font-family: monospace;
    display: block;
}

.me-card .groups {
    margin-top: 10px;
    font-size: 14px;
    text-align: center;
    color: #d8f5e3;
}

/* ---- toggle de vistas / tabs ---- */
.tabs {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 16px 0;
}

.vote-btn {
    background: #212529;
    color: #b2f2bb;
    border: none;
    border-radius: 8px;
    padding: 10px 15px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.vote-btn:hover {
    background: #000000;
}

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

.vote-btn.ghost {
    background: #e9ecef;
    color: #212529;
}

.vote-btn.ghost.active {
    background: #1971c2;
    color: #fff;
}

input[type="number"] {
    width: 56px;
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 4px;
    background: #f8f9fa;
    font-family: monospace;
    font-size: 16px;
    text-align: center;
    color: #212529;
    outline: none;
}

input[type="number"]:focus {
    border-color: #339af0;
}

/* banderitas como imagen (twemoji): el emoji nativo no se ve en Chrome/Windows */
.flag {
    height: 1em;
    width: auto;
    vertical-align: -0.12em;
    margin-right: 0.35em;
}

/* ---- partido ---- */
.stage-title {
    margin: 22px 0 8px;
    font-size: 18px;
    border-bottom: 3px solid #212529;
    padding-bottom: 4px;
}

.match {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.match.locked {
    opacity: 0.85;
    background: #f1f3f5;
}

.match .team {
    flex: 1;
    font-weight: bold;
    font-size: 14px;
}

.match .team.home {
    text-align: right;
}

.match .team.away {
    text-align: left;
}

.match .mid {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 150px;
    justify-content: center;
}

.match .vs {
    font-weight: bold;
    color: #868e96;
}

.match .vs.pending {
    opacity: 0.6;
}

.match .ko {
    font-size: 11px;
    color: #868e96;
    flex-basis: 100%;
    margin-top: 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.match .ko-save {
    padding: 4px 16px;
}

.match .pts {
    font-size: 12px;
    font-weight: bold;
    font-family: monospace;
    border-radius: 4px;
    padding: 2px 6px;
}

.pts.hit {
    background: #2b8a3e;
    color: #fff;
}

.pts.partial {
    background: #f08c00;
    color: #fff;
}

.pts.miss {
    background: #e9ecef;
    color: #868e96;
}

.realscore {
    font-family: monospace;
    font-weight: bold;
    background: #212529;
    color: #b2f2bb;
    border-radius: 4px;
    padding: 2px 8px;
}

.save-btn {
    padding: 6px 10px;
    font-size: 13px;
}

/* el botón "guardar" refleja el estado del pronóstico:
   verde = guardado, ámbar = cambios sin guardar */
.save-btn.is-saved {
    background: #2b8a3e;
    color: #fff;
}

.save-btn.is-saved:hover {
    background: #237032;
}

.save-btn.is-unsaved {
    background: #e8590c;
    color: #fff;
}

.save-btn.is-unsaved:hover {
    background: #d9480f;
}

/* pulso al recién guardar, para que se note el cambio */
.save-btn.just-saved {
    animation: savedPulse 0.4s ease;
}

@keyframes savedPulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* admin result form */
.admin-result {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 6px;
    background: #fff9db;
    border: 2px solid #fcc419;
    border-radius: 8px;
    flex-basis: 100%;
    justify-content: center;
}

.admin-result.on .vote-btn {
    background: #e8590c;
    color: #fff;
}

/* admin: cartel de la pantalla de carga */
.admin-help {
    background: #fff9db;
    border: 2px solid #fcc419;
    font-size: 13px;
}

/* admin: definir equipos de una llave (azul, distinto del form de resultado) */
.admin-result.teams {
    background: #e7f5ff;
    border-color: #4dabf7;
}

.admin-result.teams .vote-btn {
    background: #1971c2;
}

.admin-result.teams input[type="text"],
.admin-result.teams select {
    max-width: 150px;
}

.admin-result .adv-wrap {
    font-size: 11px;
    color: #495057;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.admin-result .adv-wrap select {
    max-width: 130px;
}

/* admin: botón de borrar (rojo) — gana a los .vote-btn naranja/azul de arriba */
.admin-result.on .clear-btn,
.admin-result.teams .clear-btn {
    background: #e03131;
    color: #fff;
}

/* ---- tablas de posiciones: 3 por fila, estética timbear ---- */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.group-card {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.group-head {
    background: #212529;
    color: #b2f2bb;
    font-weight: bold;
    font-size: 13px;
    text-align: center;
    padding: 4px 8px;
}

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

.standings th,
.standings td {
    padding: 3px 3px;
    text-align: center;
}

.standings th {
    font-size: 9px;
    color: #868e96;
    border-bottom: 2px solid #212529;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.standings th.pos,
.standings td.pos {
    width: 14px;
    color: #adb5bd;
}

.standings th:nth-child(n+3),
.standings td:nth-child(n+3) {
    width: 22px;
    font-family: monospace;
}

.standings th.tname,
.standings td.tname {
    text-align: left;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-left: 5px;
}

.standings td.ptscol {
    font-weight: bold;
    background: #f8f9fa;
}

.standings tbody tr:not(:last-child) td {
    border-bottom: 1px solid #f1f3f5;
}

.standings tr.qualifies {
    background: #ebfbee;
}

.standings tr.qualifies td.pos {
    color: #2b8a3e;
    font-weight: bold;
}

.standings tr.qualifies td.ptscol {
    background: #d3f9d8;
}

@media (max-width: 620px) {
    .groups-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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

/* ---- leaderboard ---- */
.lb {
    list-style: none;
    padding: 0;
    margin: 0;
}

.lb li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid #e9ecef;
}

.lb li.me {
    background: #fff3bf;
    border-radius: 6px;
    font-weight: bold;
}

.lb .rank {
    flex: 0 0 32px;
    font-family: monospace;
    font-weight: bold;
    text-align: right;
}

.lb .who {
    flex: 1;
}

.lb .pts {
    font-family: monospace;
    font-weight: bold;
}

.lb .medal {
    font-size: 18px;
}

@media (max-width: 600px) {
    /* en mobile no entra todo en una fila: apilamos centrado
       local / marcador / visita, en vez de que la visita caiga sola al costado. */
    .match {
        flex-wrap: wrap;
        gap: 4px;
    }

    .match .team,
    .match .team.home,
    .match .team.away {
        flex: 1 1 100%;
        text-align: center;
        font-size: 14px;
    }

    .match .mid {
        flex: 1 1 100%;
        min-width: 0;
    }

    .me-card .stat {
        margin: 6px 8px;
    }
}

/* ===== Bracket de llaves (knockout) ===== */
/* Scroll horizontal: el bracket es más ancho que la columna central; en mobile
   se navega arrastrando. */
/* el bracket se sale de la columna central de 760px para aprovechar todo el
   ancho de la ventana (es de doble entrada y necesita lugar); si aun así no
   entra, scrollea en horizontal. */
.bx-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 16px 12px;
    -webkit-overflow-scrolling: touch;
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.bx {
    --row: 86px;
    --gap: 14px;
    --card-w: 126px;
    --line: #ced4da;
    display: flex;
    gap: var(--gap);
    width: max-content;
    margin-inline: auto;
    align-items: flex-start;
}

.bx-col {
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--card-w);
    width: var(--card-w);
}

.bx-col-head {
    height: 22px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: #495057;
    border-bottom: 2px solid #212529;
}

/* space-around + columnas de misma altura: como cada ronda tiene la mitad de
   partidos que la anterior, cada nodo queda centrado entre los dos que lo
   alimentan, sin cálculos extra. */
.bx-col-body {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: calc(8 * var(--row));
}

.bx-match {
    flex: 0 0 var(--row);
    height: var(--row);
    display: flex;
    align-items: center;
    position: relative;
}

.bx-card {
    position: relative;
    width: 100%;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 7px;
    padding: 3px 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}

.bx-card.resolved {
    background: #f8f9fa;
}

.bx-card.tbd {
    border-style: dashed;
    opacity: .65;
}

.bx-when {
    font-size: 9px;
    color: #adb5bd;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 1px;
}

.bx-team {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: bold;
    line-height: 1.3;
}

.bx-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bx-team.win .bx-name {
    color: #2b8a3e;
}

.bx-sc {
    flex: 0 0 auto;
    min-width: 15px;
    text-align: center;
    font-family: monospace;
    font-weight: bold;
}

.bx-sc.real {
    color: #212529;
}

.bx-sc.mine {
    color: #adb5bd;
    font-size: 12px;
}

.bx-sc.lock {
    color: #ced4da;
}

.bx-card input.bx-in {
    width: 30px;
    height: 20px;
    padding: 1px;
    border: 2px solid #e9ecef;
    border-radius: 4px;
    background: #f8f9fa;
    font-family: monospace;
    font-size: 12px;
    text-align: center;
    color: #212529;
    outline: none;
}

.bx-card input.bx-in:focus {
    border-color: #339af0;
}

.bx-foot {
    margin-top: 2px;
    min-height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bx-foot-info {
    font-size: 9px;
    line-height: 1.15;
    color: #495057;
}

.bx-foot-info.muted {
    color: #adb5bd;
}

.bx-foot .pts {
    font-size: 11px;
}

.bx-save {
    width: 100%;
    padding: 2px 6px;
    font-size: 10px;
}

/* conectores. Mitad izquierda: el padre está a la derecha de sus hijos.
   Mitad derecha: espejado (padre a la izquierda). La Final recibe de las dos
   semis, una por lado. Cada nodo aporta: línea de salida hacia su padre, y (si
   tiene hijos) línea de entrada + columna vertical (spine) que une el par. */
.bx-L .bx-card::after,
.bx-R .bx-card::after,
.bx-L:not(.bx-r32) .bx-card::before,
.bx-R:not(.bx-r32) .bx-card::before,
.bx-final .bx-card::before,
.bx-final .bx-card::after {
    content: '';
    position: absolute;
    top: 50%;
    margin-top: -1px;
    width: calc(var(--gap) / 2);
    height: 2px;
    background: var(--line);
}

/* líneas que salen hacia la DERECHA del nodo */
.bx-L .bx-card::after,
.bx-R:not(.bx-r32) .bx-card::before,
.bx-final .bx-card::after {
    left: 100%;
}

/* líneas que salen hacia la IZQUIERDA del nodo */
.bx-R .bx-card::after,
.bx-L:not(.bx-r32) .bx-card::before,
.bx-final .bx-card::before {
    right: 100%;
}

/* columna vertical (spine) que une cada par de hijos, del lado de los hijos */
.bx-conn {
    display: none;
}

.bx-L:not(.bx-r32) .bx-conn,
.bx-R:not(.bx-r32) .bx-conn {
    display: block;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    background: var(--line);
}

.bx-L:not(.bx-r32) .bx-conn {
    right: 100%;
    margin-right: calc(var(--gap) / 2 - 1px);
}

.bx-R:not(.bx-r32) .bx-conn {
    left: 100%;
    margin-left: calc(var(--gap) / 2 - 1px);
}

/* altura del spine = distancia entre los centros de los dos hijos, que se
   duplica cada ronda. */
.bx-r16 .bx-conn {
    height: calc(1 * var(--row));
}

.bx-qf .bx-conn {
    height: calc(2 * var(--row));
}

.bx-sf .bx-conn {
    height: calc(4 * var(--row));
}

/* la Final va al centro vertical (alineada con las semis) y el 3er puesto se
   mete justo abajo, en el hueco central del bracket, sin sumar altura. */
.bx-C .bx-col-body {
    justify-content: flex-start;
}

.bx-C .bx-col-body > .bx-match:first-child {
    margin-top: calc(3.5 * var(--row));
}

.bx-bronze-slot {
    margin-top: 8px;
    text-align: center;
}

.bx-bronze-cap {
    font-size: 11px;
    font-weight: bold;
    color: #868e96;
    margin-bottom: 3px;
}

.bx-bronze-slot .bx-card::before,
.bx-bronze-slot .bx-card::after {
    content: none;
}

@media (max-width: 600px) {
    .bx {
        --row: 82px;
        --card-w: 118px;
        --gap: 10px;
    }
}

/* ===== Fase de grupos compacta (estilo fixture de bolsillo) ===== */
.gp-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.gp-card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, .05);
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, .05);
    overflow: hidden;
}

.gp-head {
    background: #212529;
    color: #b2f2bb;
    font-weight: bold;
    font-size: 13px;
    text-align: center;
    padding: 4px 8px;
}

.gp-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    min-height: 30px;
    font-size: 12px;
    border-bottom: 1px solid #f1f3f5;
}

.gp-row:last-child {
    border-bottom: none;
}

.gp-row.locked {
    background: #f8f9fa;
}

.gp-when {
    flex: 0 0 36px;
    font-size: 9px;
    line-height: 1.1;
    color: #adb5bd;
    font-family: monospace;
}

.gp-home,
.gp-away {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: bold;
    min-width: 0;
}

.gp-home {
    justify-content: flex-end;
    text-align: right;
}

.gp-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gp-home .flag {
    margin: 0;
}

.gp-away .flag {
    margin: 0;
}

.gp-mid {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 54px;
}

.gp-dash {
    color: #868e96;
    font-weight: bold;
}

.gp-lock {
    color: #ced4da;
    font-size: 11px;
}

.gp-card input.gp-in {
    width: 26px;
    height: 22px;
    padding: 1px;
    border: 2px solid #e9ecef;
    border-radius: 4px;
    background: #f8f9fa;
    font-family: monospace;
    font-size: 12px;
    text-align: center;
    color: #212529;
    outline: none;
}

.gp-card input.gp-in:focus {
    border-color: #339af0;
}

.gp-act {
    flex: 0 0 68px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.gp-save {
    padding: 2px 6px;
    font-size: 10px;
    white-space: nowrap;
}

.gp-mine {
    font-size: 10px;
    color: #adb5bd;
    font-family: monospace;
}

.gp-row .realscore {
    font-size: 11px;
    padding: 1px 5px;
}

.gp-row .pts {
    font-size: 9px;
    padding: 1px 6px;
    letter-spacing: .2px;
}

.gp-row .pts b {
    font-size: 11px;
    font-weight: bold;
}

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