/* ========================================
   ARBRE DU BRACKET (vue par défaut)
   Page publique d'un jeu en « Bracket » : templates/home/_bracket_arbre.html
   ======================================== */

/* display:flex des conteneurs l'emporterait sur l'attribut hidden posé par la bascule */
.tournament-phases-wrapper[hidden],
.bk-section[hidden] { display: none !important; }

/* ---------- Bascule Vue bracket / Vue détaillée ---------- */
.bk-bascule {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.35rem;
    margin: -2rem 0 2.5rem;
    border-radius: 14px;
    background: rgba(var(--jc-surface-rgb, 20, 24, 50), 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.bk-bascule__btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}

.bk-bascule__btn:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }

.bk-bascule__btn.is-actif {
    color: var(--jc-bg, #0a0e27);
    background: var(--jc-accent, #d4af37);
}

/* ---------- Panneau ---------- */
.bk-astuce {
    display: none;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 0.8rem;
}

/* Pleine largeur : l'arbre sort de la marge intérieure de la section (tournament.css : 4rem, 2rem sous 768px,
   1rem sous 480px) pour laisser toute la place au bracket */
#tournament .bk-section { margin-inline: -4rem; }

.bk-defilement {
    overflow-x: auto;
    padding: 1.5rem 1rem;
    border-radius: 18px;
    background: linear-gradient(160deg, rgba(var(--jc-surface-rgb, 20, 24, 50), 0.85), rgba(var(--jc-bg-rgb, 12, 16, 35), 0.75));
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.4) transparent;
}

.bk-defilement:focus-visible { outline: 2px solid rgba(var(--jc-accent-rgb, 212, 175, 55), 0.5); }

.bk-arbre {
    --bk-largeur: 230px;
    --bk-ecart: 3rem;
    --bk-trait: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: flex-start;
    gap: var(--bk-ecart);
    width: max-content;
    margin: 0 auto;
}

.bk-lignes {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.bk-ligne__titre {
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--jc-accent, #d4af37);
    margin-bottom: 0.6rem;
}

.bk-ligne--losers {
    padding-top: 2rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.bk-ligne--losers .bk-ligne__titre { color: #f87171; }

/* ---------- Tours (colonnes) ---------- */
.bk-tours {
    display: flex;
    align-items: stretch;
    gap: var(--bk-ecart);
}

.bk-tour {
    display: flex;
    flex-direction: column;
    width: var(--bk-largeur);
    scroll-snap-align: start;
}

.bk-tour__titre {
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bk-tour--finale .bk-tour__titre,
.bk-tour--champion .bk-tour__titre { color: var(--jc-accent, #d4af37); background: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.08); }

.bk-tour__matchs { flex: 1; display: flex; flex-direction: column; }

/* Chaque paire, puis chaque match, prend une part égale de la hauteur : les milieux s'alignent d'un tour à l'autre */
.bk-paire { flex: 1; display: flex; flex-direction: column; position: relative; }

.bk-slot {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0.4rem 0;
    position: relative;
}

.bk-slot > * { width: 100%; }

/* ---------- Traits ---------- */
.bk-tour--sortie .bk-slot::after,
.bk-tour--entree .bk-slot::before {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(var(--bk-ecart) / 2);
    border-top: 2px solid var(--bk-trait);
}

.bk-tour--sortie .bk-slot::after { left: 100%; }
.bk-tour--entree .bk-slot::before { right: 100%; }

/* Trait vertical qui réunit deux matchs vers le match suivant */
.bk-tour--relie .bk-paire--double::after {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    left: calc(100% + var(--bk-ecart) / 2 - 1px);
    border-left: 2px solid var(--bk-trait);
}

/* ---------- Match ---------- */
.bk-match {
    background: linear-gradient(145deg, rgba(var(--jc-surface-rgb, 20, 24, 50), 0.95), rgba(var(--jc-bg-rgb, 12, 16, 35), 0.9));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.bk-match--termine { border-color: rgba(34, 197, 94, 0.25); }
.bk-match--en_cours { border-color: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.5); }
.bk-tour--finale .bk-match { border-color: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.5); box-shadow: 0 0 18px rgba(var(--jc-accent-rgb, 212, 175, 55), 0.15); }

.bk-match__entete {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.6rem;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.bk-match__etat--live { color: #fbbf24; text-transform: uppercase; }

.bk-match__point {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 4px;
    border-radius: 50%;
    background: #fbbf24;
    animation: bk-pulse 1.4s ease-in-out infinite;
}

@keyframes bk-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---------- Ligne d'équipe ---------- */
.bk-equipe {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-left: 3px solid var(--bk-couleur, #666);
    transition: background 0.2s, opacity 0.2s;
    outline: none;
}

.bk-match .bk-equipe + .bk-equipe { border-top: 1px solid rgba(255, 255, 255, 0.05); }

.bk-equipe__logo {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.6rem;
    font-weight: 800;
    /* --bk-texte : blanc, ou bleu nuit sur une couleur d'équipe claire (filtre texte_sur_couleur) */
    color: var(--bk-texte, #fff);
    background: var(--bk-couleur, rgba(255, 255, 255, 0.06));
}

.bk-equipe__logo img { width: 100%; height: 100%; object-fit: cover; }
.bk-equipe__logo--rond { border-radius: 50%; }

.bk-equipe__nom {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bk-equipe__score {
    min-width: 1.6rem;
    text-align: center;
    font-weight: 900;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    padding: 0.1rem 0.3rem;
}

.bk-equipe--gagnant { background: rgba(34, 197, 94, 0.08); }
.bk-equipe--gagnant .bk-equipe__nom { color: #4ade80; }
.bk-equipe--gagnant .bk-equipe__score { color: #4ade80; background: rgba(34, 197, 94, 0.15); }
.bk-equipe--perdant { opacity: 0.5; }

/* Badge des bonus du match (détail dans la bulle .bk-bulle au survol) */
.bk-bonus {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: var(--jc-accent, #d4af37);
    background: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.14);
    border: 1px solid rgba(var(--jc-accent-rgb, 212, 175, 55), 0.45);
    cursor: help;
}

.bk-bonus i { font-size: 0.62rem; }
.bk-bonus--malus { color: #f87171; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.45); }

/* Bulle posée par-dessus la page : le cadre défilant de l'arbre la couperait */
.bk-bulle {
    position: fixed;
    z-index: 1500;
    max-width: 280px;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    background: rgba(var(--jc-bg-rgb, 10, 14, 39), 0.97);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
}

.bk-bulle.is-visible { opacity: 1; transform: none; }

.bk-bulle__titre {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 0.45rem;
}

.bk-bulle__liste { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }

.bk-equipe--vide { border-left-color: rgba(255, 255, 255, 0.1); }
.bk-equipe--vide .bk-equipe__logo { background: rgba(255, 255, 255, 0.04); border: 1px dashed rgba(255, 255, 255, 0.15); }
.bk-equipe--vide .bk-equipe__nom { color: rgba(255, 255, 255, 0.35); font-style: italic; font-weight: 500; }

/* Suivi d'une équipe au survol : les autres s'effacent */
.bk-arbre--suivi .bk-equipe:not(.bk-suivi),
.bk-arbre--suivi .bk-champion:not(.bk-suivi) { opacity: 0.25; }
.bk-equipe.bk-suivi { opacity: 1; background: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.14); }

/* ---------- Poules ---------- */
.bk-poules {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: var(--bk-largeur);
    flex-shrink: 0;
    scroll-snap-align: start;
}

.bk-poule__titre {
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--jc-secondary-light, #93c5fd);
    background: rgba(var(--jc-secondary-rgb, 59, 130, 246), 0.08);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.bk-poule__liste {
    list-style: none;
    margin: 0;
    padding: 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(var(--jc-secondary-rgb, 59, 130, 246), 0.2);
    background: rgba(var(--jc-surface-rgb, 20, 24, 50), 0.9);
}

.bk-poule__liste .bk-equipe + .bk-equipe { border-top: 1px solid rgba(255, 255, 255, 0.05); }
.bk-poule__rang { width: 1rem; font-size: 0.75rem; font-weight: 800; color: rgba(255, 255, 255, 0.4); text-align: center; }
.bk-poule__bilan { font-size: 0.78rem; font-weight: 800; color: rgba(255, 255, 255, 0.7); }

/* ---------- Champion ---------- */
.bk-champion {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0.8rem;
    border-radius: 12px;
    text-align: center;
    background: radial-gradient(circle at 50% 0%, rgba(var(--jc-accent-rgb, 212, 175, 55), 0.25), rgba(var(--jc-surface-rgb, 20, 24, 50), 0.95) 70%);
    border: 1px solid rgba(var(--jc-accent-rgb, 212, 175, 55), 0.6);
    box-shadow: 0 0 24px rgba(var(--jc-accent-rgb, 212, 175, 55), 0.2);
    transition: opacity 0.2s;
    outline: none;
}

.bk-champion__trophee { font-size: 1.6rem; color: var(--jc-accent, #d4af37); }
.bk-champion__logo { width: 52px; height: 52px; font-size: 0.9rem; }
.bk-champion__nom { font-weight: 900; font-size: 0.95rem; color: var(--jc-accent, #d4af37); }

/* ---------- Grand tableau (un tour de 16 matchs ou plus : seizièmes, trente-deuxièmes) : matchs resserrés ---------- */
.bk-arbre--compact { --bk-ecart: 2.25rem; }
.bk-arbre--compact .bk-slot { padding: 0.15rem 0; }
.bk-arbre--compact .bk-match__entete { padding: 0.1rem 0.5rem; font-size: 0.58rem; }
.bk-arbre--compact .bk-equipe { gap: 0.4rem; padding: 0.2rem 0.5rem; }
.bk-arbre--compact .bk-equipe__logo { width: 20px; height: 20px; font-size: 0.52rem; }
.bk-arbre--compact .bk-equipe__nom { font-size: 0.76rem; }
.bk-arbre--compact .bk-equipe__score { font-size: 0.82rem; padding: 0 0.3rem; }
/* « Trente-deuxièmes de finale » doit tenir dans la colonne */
.bk-arbre--compact .bk-tour__titre { font-size: 0.66rem; letter-spacing: 0.6px; }

/* ---------- Mobile : l'arbre défile horizontalement, colonnes un peu plus étroites ---------- */
@media (max-width: 768px) {
    .bk-bascule { margin: -1rem 0 1.5rem; display: flex; }
    .bk-bascule__btn { flex: 1 1 auto; justify-content: center; padding: 0.55rem 0.6rem; font-size: 0.78rem; }
    .bk-astuce { display: block; }
    #tournament .bk-section { margin-inline: -2rem; }
    .bk-defilement { padding: 1rem 0.75rem; }
    .bk-arbre { --bk-largeur: 190px; --bk-ecart: 2rem; margin: 0; }
    .bk-equipe__nom { font-size: 0.76rem; }
}

@media (max-width: 480px) {
    #tournament .bk-section { margin-inline: -1rem; }
}


/* ---------- Détail d'un match (ancienne « Vue détaillée ») ---------- */
.bk-match[data-detail] { cursor: pointer; transition: border-color .2s, transform .2s; }
.bk-match[data-detail]:hover { border-color: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.6); transform: translateY(-1px); }
.bk-match[data-detail]:focus-visible { outline: 2px solid var(--jc-accent, #d4af37); outline-offset: 2px; }

.bk-poule__matchs { margin-top: 0.5rem; }
.bk-poule__matchs summary {
    display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
    padding: 0.35rem 0.6rem; border-radius: 8px; cursor: pointer; list-style: none;
    font-size: 0.72rem; font-weight: 700; color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06);
}
.bk-poule__matchs summary::-webkit-details-marker { display: none; }
.bk-poule__matchs summary i { font-size: 0.65rem; transition: transform .2s; }
.bk-poule__matchs[open] summary i { transform: rotate(180deg); }
.bk-poule__matchs-liste { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }

.bk-detail { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.bk-detail[hidden] { display: none; }
.bk-detail__fond { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(3px); }
.bk-detail__boite { position: relative; width: min(460px, 100%); max-height: calc(100vh - 2rem); overflow-y: auto; padding-top: 2.75rem; }
/* La carte vient de l'ancienne grille (max-width 42 %) : toute la largeur de la fenêtre */
.bk-detail__boite .mc { margin: 0; width: 100%; max-width: none; }
.bk-detail__fermer {
    position: absolute; top: 0; right: 0; z-index: 2; width: 2rem; height: 2rem;
    display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; cursor: pointer;
    color: #fff; background: rgba(var(--jc-bg-rgb, 10, 14, 39), 0.85); border: 1px solid rgba(255, 255, 255, 0.25);
}
.bk-detail__fermer:hover, .bk-detail__fermer:focus-visible { color: var(--jc-bg, #0a0e27); background: var(--jc-accent, #d4af37); }
body.bk-detail-ouvert { overflow: hidden; }

/* ---------- Rondes suisses (apps/home/suisse.py) : classement en tête, une colonne par ronde ---------- */
.bk-ligne--suisse .bk-ligne__titre { color: var(--jc-secondary-light, #93c5fd); }
.bk-match__bilan {
    margin-left: 0.3rem; padding: 0 0.35rem; border-radius: 6px; font-weight: 800;
    color: var(--jc-accent, #d4af37); background: rgba(var(--jc-accent-rgb, 212, 175, 55), 0.12);
}
.bk-suisse__statut { color: #4ade80; font-size: 0.8rem; }
.bk-suisse__statut--elimine { color: #f87171; }
.bk-suisse--elimine .bk-equipe__nom { opacity: 0.55; }
.bk-suisse--qualifie { box-shadow: inset 3px 0 0 var(--jc-accent, #d4af37); }
.bk-suisse__buchholz { margin-left: 0.35rem; font-size: 0.65rem; font-weight: 700; color: rgba(255, 255, 255, 0.45); }
.bk-suisse__legende { margin: 0.45rem 0.2rem 0; font-size: 0.68rem; line-height: 1.35; color: rgba(255, 255, 255, 0.45); }
