/* ============ Couleurs ============ */
:root {
  --text: #fff;
  --sub: #cfd3da;
  --placeholder: #8a8f99;
  --card-bg: rgba(10, 12, 18, .55);
  --card-bg-ph: rgba(255, 255, 255, .06);
  --border-ph: rgba(255, 255, 255, .18);
  --gold: #ffd166;
  --header: #ffd166;
  color-scheme: dark;
}

/* ============ Polices (fichiers .otf dans assets/fonts) ============ */
@font-face { font-family: 'Akira Expanded'; src: url('../assets/fonts/AkiraExpanded.otf') format('opentype'); }
@font-face { font-family: 'Xtradex'; src: url('../assets/fonts/Xtradex.otf') format('opentype'); }

/* ============ Base ============ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: transparent;
}

/* Aucun défilement : la page est réduite pour tenir dans l'écran (voir fitToScreen) */
html, body {
  height: 100%;
  overflow: hidden; /* repli pour les navigateurs sans "clip" */
  overflow: clip;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  color: var(--text);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.wrap {
  width: max-content;
  padding: 16px 44px 30px 18px; /* à droite : place pour le score de la Grande Finale */
  transform-origin: top left;
}

/* ============ Barre du haut (boutons) ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 32px; /* espace avant l'Upper Bracket */
  /* les onglets passent à la ligne au lieu d'élargir la page */
  width: 0;
  min-width: 100%;
}

.actions {
  display: flex;
  gap: 8px;
  margin-left: auto; /* boutons à droite */
}

/* Même style sombre que les onglets (police Segoe UI : accents corrects) */
.actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(10, 12, 18, .55);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.actions button:hover    { background: rgba(40, 44, 56, .75); border-color: rgba(255, 255, 255, .35); }
.actions button:disabled { opacity: .4; cursor: default; }
.actions button:disabled:hover { background: rgba(10, 12, 18, .55); border-color: rgba(255, 255, 255, .15); }

.actions svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Remises à zéro : rouge discret, plein quand une confirmation est demandée */
.actions .danger       { color: #ff8f8f; border-color: rgba(255, 90, 90, .35); }
.actions .danger:hover { background: rgba(190, 35, 35, .25); border-color: rgba(255, 90, 90, .7); }
.actions .danger.armed { background: #c62828; border-color: #ff8f8f; color: #fff; }

/* Largeur fixe : le bouton ne bouge pas quand il affiche "Confirmer ?" */
#reset     { min-width: 148px; }
#reset-all { min-width: 180px; }

/* ============ Onglets (un bracket par onglet) ============ */
.tabs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px 11px 20px;
  border-radius: 10px 10px 0 0;
  background: rgba(10, 12, 18, .55);
  border: 1px solid rgba(255, 255, 255, .15);
  border-bottom: none;
  color: var(--sub);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  max-width: 280px;
}
.tab:hover  { background: rgba(40, 44, 56, .75); color: #fff; }
.tab.active {
  background: rgba(30, 34, 46, .95);
  color: #fff;
  box-shadow: inset 0 2px 0 var(--gold);
}

.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  outline: none;
}
.tab-name[contenteditable="true"] {
  cursor: text;
  background: rgba(255, 255, 255, .12);
  padding: 0 3px;
  border-radius: 3px;
}

.tab-close,
.tab-rename {
  border: none;
  background: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 5px;
  cursor: pointer;
  opacity: .6;
}
.tab-rename { font-size: 15px; }
.tab-close:hover,
.tab-rename:hover { opacity: 1; background: rgba(255, 255, 255, .15); }

#add-tab {
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(10, 12, 18, .55);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  margin-left: 2px;
}
#add-tab:hover { background: rgba(40, 44, 56, .75); }

/* ============ Mise en page ============ */
.layout {
  display: flex;
  gap: 26px; /* écart entre les brackets et la Grande Finale */
  align-items: stretch;
}

.left {
  flex: 1 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.right {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 230px;
}

.section-title {
  font-family: 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--header);
  text-transform: uppercase;
  margin: 14px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 209, 102, .3);
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9);
}

/* ============ Bracket ============ */
.bracket {
  /* 5 colonnes réparties sur toute la largeur ; Upper et Lower restent alignés */
  display: grid;
  grid-template-columns: repeat(5, 200px);
  justify-content: space-between;
  column-gap: 60px; /* espace minimum entre les rounds */
  padding-bottom: 8px;
}

.col {
  display: flex;
  flex-direction: column;
}

/* Les matchs se répartissent sur toute la hauteur : chaque match tombe
   pile au milieu des deux matchs du round précédent.
   (marges plutôt que gap, sinon le centrage est faussé) */
.col-matches {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.col-matches > .match-wrap { margin: 14px 0; } /* espace vertical entre les matchs */

.col-label {
  margin-bottom: 14px; /* espace entre le nom du round et les matchs */
  font-size: 10px;
  color: var(--sub);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .8;
}

/* ============ Carte de match ============ */
.match-wrap { position: relative; } /* sert d'ancre au rectangle de score */

.match {
  background: var(--card-bg);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

.mid { /* identifiant du match (M1, M2…) */
  font-size: 9px;
  color: var(--sub);
  padding: 2px 7px;
  background: rgba(0, 0, 0, .35);
}

/* ============ Emplacement d'équipe ============ */
.slot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  min-height: 34px;
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}

.slot.team {
  color: #fff;
  font-family: 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  letter-spacing: .4px;
  cursor: pointer;
}
.slot.team:hover     { filter: brightness(1.12); }
.slot.team.disabled  { cursor: default; }

.slot.ph { /* équipe pas encore connue */
  background: var(--card-bg-ph);
  color: var(--placeholder);
  font-weight: 500;
  font-style: italic;
  font-size: 12px;
  border-top: 1px dashed var(--border-ph);
}

.slot.winner { box-shadow: inset 0 0 0 2px var(--gold); }
.slot.loser  { opacity: .4; }

/* Grand vainqueur (gagnant de la Grande Finale) */
.slot.champion {
  background: linear-gradient(135deg, #b8860b, #ffd700 50%, #b8860b);
  box-shadow: inset 0 0 0 2px #fff3b0, 0 0 14px rgba(255, 215, 0, .6);
}

/* Glissement quand une équipe arrive dans le match suivant */
.slot.slide-in { animation: slide-in .45s cubic-bezier(.22, 1, .36, 1); }

@keyframes slide-in {
  from { transform: translateX(-60px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}

/* Score inscrit à côté du nom une fois le match joué */
.slot .score {
  margin-left: auto;
  padding-left: 6px;
  font-family: 'Xtradex', 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 21px;
  line-height: 1;
}

/* ============ Rectangle de saisie du score ============ */
.score-drawer {
  position: absolute;
  left: calc(100% + 3px); /* petit espace pour voir les coins arrondis côté carte */
  width: 34px;
  overflow: hidden; /* le panneau sort de derrière la carte */
  z-index: 5;
}

.score-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffcf4d;
  border-radius: 8px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, .45);
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.22, 1, .36, 1);
}
.score-drawer.open .score-panel { transform: translateX(0); }

.score-panel input {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  text-align: center;
  font-family: 'Xtradex', 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 22px;
  color: #16161a;
  caret-color: transparent;
}
.score-panel input + input { border-top: 1px solid rgba(0, 0, 0, .15); }
.score-panel input:focus { background: rgba(0, 0, 0, .1); }
.score-panel input::placeholder { color: rgba(0, 0, 0, .25); }

/* Égalité refusée : le panneau tremble */
.score-panel.tie { animation: shake .3s; }
@keyframes shake {
  25% { margin-left: -4px; }
  75% { margin-left: 4px; }
}

.logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}

/* ============ Fenêtre des compositions (MAJ + clic) ============ */
.roster-panel {
  /* Distance entre le contenu de la fenêtre et le bord droit de l'écran.
     Le fond de la fenêtre va jusqu'au bord droit : le bracket n'est plus visible derrière. */
  --roster-offset: 150px;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: calc(260px + var(--roster-offset));
  max-width: 100vw;
  overflow-y: auto;
  scrollbar-width: none; /* défile à la molette, sans barre visible */
  padding: 12px calc(12px + var(--roster-offset)) 20px 12px;
  background: rgb(16, 18, 26);
  border-left: 1px solid rgba(255, 255, 255, .12);
  box-shadow: -8px 0 28px rgba(0, 0, 0, .55);
  /* Fermée : cachée hors de l'écran à droite. Fermeture = glisse vers la droite */
  transform: translateX(100%);
  opacity: 0;
  visibility: hidden;
  transition: transform .4s cubic-bezier(.55, 0, .45, 1),
              opacity .4s ease-in,
              visibility 0s .4s;
  z-index: 50;
}
.roster-panel::-webkit-scrollbar { display: none; }
/* Ouverte : glisse depuis la droite */
.roster-panel.open {
  transform: none;
  opacity: 1;
  visibility: visible;
  transition: transform .4s cubic-bezier(.22, 1, .36, 1),
              opacity .25s ease-out;
}

.roster-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.roster-title {
  font-family: 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--header);
}
.roster-close {
  border: none;
  background: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 0 6px;
  border-radius: 6px;
  cursor: pointer;
  opacity: .7;
}
.roster-close:hover { opacity: 1; background: rgba(255, 255, 255, .12); }

.roster-team {
  margin-bottom: 10px;
  border-radius: 7px;
  overflow: hidden;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .1);
}
.roster-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-family: 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}
.roster-head .logo { width: 22px; height: 22px; }

/* Classement Stage 3, à droite du nom */
.roster-rank {
  margin-left: auto;
  padding-left: 6px;
  font-size: 12px;
}

.roster-region {
  padding: 12px 10px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--gold);
}

.roster-list { list-style: none; margin: 0; padding: 2px 0 6px; }
.roster-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 600;
}
/* Icône de rôle devant le pseudo */
.role-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
}
.role-icon svg { width: 13px; height: 13px; fill: currentColor; }

/* ============ Classement (Ctrl + clic) ============ */
.st-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

/* Place : même police et même doré que les titres du site */
.st-place {
  flex-shrink: 0;
  width: 42px;
  font-family: 'Akira Expanded', 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  text-align: center;
  color: var(--sub);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
}
.st-row.gold .st-place   { color: #ffd700; font-size: 18px; }
.st-row.silver .st-place { color: #d4dbe3; font-size: 16px; }
.st-row.bronze .st-place { color: #d9955a; font-size: 15px; }

.st-card { flex: 1; min-width: 0; }
.st-row.silver .st-card { box-shadow: 0 0 0 1px #d4dbe3, 0 2px 8px rgba(0, 0, 0, .4); }
.st-row.bronze .st-card { box-shadow: 0 0 0 1px #d9955a, 0 2px 8px rgba(0, 0, 0, .4); }

/* Animations désactivées si Windows le demande */
@media (prefers-reduced-motion: reduce) {
  .slot.slide-in, .score-panel.tie { animation: none; }
  .score-panel, .roster-panel, .roster-panel.open { transition: none; }
}

/* ============ Grande Finale ============ */
.gf       { width: 230px; }
.gf .slot { font-size: 15px; min-height: 42px; }
.gf .logo { width: 28px; height: 28px; }
