h1 {
  text-align: center;
}
.red { color: red; }

/* =========================================================
   Variables : toutes les dimensions dépendent d'elles.
   Les media queries ne modifient que ces variables.
   ========================================================= */
.ranking-table-container {
  --h: 220px;                      /* hauteur des en-têtes */
  --col-w: 46px;                   /* largeur d'une colonne d'épreuve */
  --name-w: 180px;                 /* largeur de la colonne nom */
  --fs-body: 14px;                 /* taille du texte du corps */
  --fs-head: 13px;                 /* taille du texte des en-têtes */
  --cell-py: 6px;                  /* padding vertical des cellules */

  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* inclinaison de la dernière colonne : --h × tan(30°) ≈ --h × 0.577 */
  padding-right: calc(var(--h) * 0.577 + 12px);
  box-sizing: border-box;
  font-size: var(--fs-body);
}

/* Tablette */
@media (max-width: 1024px) {
  .ranking-table-container {
    --h: 190px;
    --col-w: 40px;
    --name-w: 150px;
    --fs-body: 13px;
    --fs-head: 12px;
  }
}

/* Mobile */
@media (max-width: 600px) {
  .ranking-table-container {
    --h: 150px;
    --col-w: 34px;
    --name-w: 120px;
    --fs-body: 12px;
    --fs-head: 11px;
    --cell-py: 4px;
  }
}

/* Très petit écran */
@media (max-width: 380px) {
  .ranking-table-container {
    --h: 130px;
    --col-w: 30px;
    --name-w: 100px;
    --fs-body: 11px;
    --fs-head: 10px;
  }
}

/* =========================================================
   Table
   ========================================================= */
.ranking-table-container table.dataTable {
  width: max-content !important;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

/* ---------- corps ---------- */
.ranking-table-container table.dataTable tbody td {
  border: 1px solid #ccc;
  padding: var(--cell-py) 2px;
  text-align: center;
  box-sizing: border-box;
}
.ranking-table-container table.dataTable tbody td.bonus {
  background-color: #FFC7CE;
}
.ranking-table-container table.dataTable tbody td.best10 {
  background-color: #ffff00;
}
.ranking-table-container table.dataTable tbody td.tickets {
  background-color: #E36868;
}
.ranking-table-container table.dataTable tbody td.rose {
  color: #FF2EA8;
  font-style: italic;
}
.ranking-table-container table.dataTable tbody tr.select td {
  background-color: lightcyan !important;
  font-weight: bold;
}
.ranking-table-container table.dataTable tbody td:nth-child(3) {
  text-align: left;
  padding-left: 6px;
  /* évite que les longs noms cassent la mise en page */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* colonnes d'épreuves bleues une sur deux, comme Excel */
.ranking-table-container table.dataTable tbody td:nth-child(odd):not(:first-child):not(:nth-last-child(-n+4)) {
  background: #dce6f1;
}
.ranking-table-container table.dataTable tbody td:nth-last-child(-n+4) {
  font-weight: bold;
}

/* ---------- en-têtes ---------- */
.ranking-table-container table.dataTable th.rotate {
  --w: var(--col-w);                           /* largeur d'une colonne */
  --head-bg: #fff;
  position: relative;
  box-sizing: border-box;
  width: var(--w) !important;
  min-width: var(--w) !important;
  max-width: var(--w) !important;
  height: var(--h);
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  background-image: none !important;
  overflow: visible !important;
  cursor: default;
}
.ranking-table-container table.dataTable th.event-column-lastname { --w: var(--name-w); }
.ranking-table-container table.dataTable th.head-fixed { --head-bg: #ffff00; }
.ranking-table-container table.dataTable th.head-event:nth-child(odd)  { --head-bg: #dce6f1; }
.ranking-table-container table.dataTable th.head-event:nth-child(even) { --head-bg: #fff; }

/* la forme : parallélogramme (côtés à 60°) */
.ranking-table-container .h-shape {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  background: var(--head-bg);
  border: 1px solid #333;
  transform: skewX(-30deg);
  transform-origin: 0 100%;
}

/* le texte : suit la ligne médiane du parallélogramme */
.ranking-table-container .h-text {
  position: absolute;
  left: calc(var(--w) / 2);       /* part du milieu du bord bas */
  bottom: 0;
  width: calc(var(--h) * 1.05);   /* longueur proportionnelle à la hauteur (230px pour 220px) */
  padding-left: 8px;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--fs-head);
  font-weight: bold;
  line-height: 1.2;
  text-align: left;
  transform-origin: 0 50%;
  transform: translateY(50%) rotate(-60deg);
  z-index: 1;
}

/* DataTables : flèches de tri */
.ranking-table-container table.dataTable thead .dt-column-order,
.ranking-table-container table.dataTable thead th::before,
.ranking-table-container table.dataTable thead th::after {
  display: none !important;
}

/* ---------- formulaire ---------- */
#form-magiclink {
  width: auto;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 12px;
  box-sizing: border-box;
}
#form-magiclink input,
#form-magiclink select,
#form-magiclink button {
  max-width: 100%;
  box-sizing: border-box;
}
@media (max-width: 600px) {
  #form-magiclink input,
  #form-magiclink select,
  #form-magiclink button {
    width: 100%;
    font-size: 16px;               /* évite le zoom automatique sur iOS */
  }
}

/* =========================================================
   Optimisations mobile supplémentaires
   ========================================================= */

/* Empêche le défilement horizontal du tableau de faire "tirer" la page */
.ranking-table-container {
  overscroll-behavior-x: contain;
}

/* Barre de recherche DataTables sur toute la largeur */
@media (max-width: 600px) {
  .dt-search,
  .dataTables_filter {
    float: none !important;
    text-align: left !important;
    margin-bottom: 8px;
  }
  .dt-search input,
  .dataTables_filter input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-left: 0 !important;
    font-size: 16px;               /* évite le zoom auto sur iOS */
  }

  /* On masque la colonne "Participation" pour gagner de la place */
  .ranking-table-container table.dataTable th:nth-child(2),
  .ranking-table-container table.dataTable td:nth-child(2) {
    display: none;
  }

  /* Colonne "Nom / Prénom" figée à gauche pendant le défilement */
  .ranking-table-container table.dataTable tbody td:nth-child(3) {
    position: sticky;
    left: 0;
    z-index: 2;
    box-shadow: 2px 0 3px rgba(0, 0, 0, .15);
  }
}