/* ========================================
   VARIABLES GLOBALES
   ======================================== */
:root {
    --bg-dark: #000000;
    --bg-dark-grey: #4B5563;
    --bg-board: #E1ED76;
    --primary-blue: #2563EB;
    --primary-blue-hover: #1D4ED8;
    --light-blue: #3399ff;
    --light-blue-plus: #72C4FE;
    --card-bg: #FFFFFF;
    --card-bg2: #ebf4fe;
    --card-placeholder-bg: #E1ED76;
    --card-placeholder-border: rgba(36, 136, 102, 0.25);
    --text-light: #FFFFFF;
    --text-dark: #1F2937;
    --danger-red: #b90707;
    --danger-red-hover: #d80303;
}

/* ========================================
   RESET & BASE STYLES
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.card,
.card img {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    height: 100vh;
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0 auto;
    background-color: var(--bg-dark);
}

/* ========================================
   HEADER & NAVIGATION
   ======================================== */
.header {
    padding: 12px 20px;
    display: flex;
    border-bottom: 1px solid #333;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* Player Dropdown */
.player-dropdown {
    position: relative;
}

.player-dropdown-button {
    background: none;
    border: 1px solid var(--primary-blue);
    border-radius: 8px;
    padding: 8px 16px;
    color: var(--primary-blue);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.player-dropdown-button:hover {
    background-color: var(--primary-blue-hover);
}

.player-dropdown-button img {
    width: 23px;
    height: 23px;
    fill: var(--primary-blue);
}

.player-dropdown-button:hover img {
    fill: var(--primary-blue-hover);
}

/* ========================================
   TAB BAR (NAVIGATION JOUEURS)
   ======================================== */
.tab-bar {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    padding: 0;
}

.tab-bar-nav {
    width: 100%;
    padding: 12px 0 0 0;
}

.tab-bar-list {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    gap: 12px;
    list-style: none;
    padding: 0 3%;
    margin: 0;
}

.tab-bar-item {
    display: flex;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s, background 0.5s ease;
    position: relative;
    border: var(--light-blue) 1px solid;
    border-radius: 8px;
    background: none;
    padding: 8px 12px;
    width: auto;
    min-width: unset;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
}

.tab-bar-item.active {
    border: var(--bg-board) 1px solid;
}

.tab-bar-label {
    color: var(--light-blue);
    font-size: 18px;
    letter-spacing: 0.5px;
    transition: color 0.2s, font-size 0.2s, font-weight 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    display: inline-block;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
}

.tab-bar-label.active {
    color: #F7FA8A;
    font-weight: bold;
    font-size: 20px;
    text-shadow: 0px 0px 8px rgba(0, 0, 0, 0.5);
}

/* ========================================
   PROGRESS BAR
   ======================================== */
.progress-section {
    padding: 10px 16px 10px 16px;
    margin: 3px 10px 3px 10px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.progress-track {
    background-color: #ffffff;
    height: 40px;
    border: #9197a3 2px solid;
    border-radius: 20px;
    position: relative;
    overflow: visible;
}

.progress-track::after {
    content: '';
    position: absolute;
    left: 2%;
    top: 50%;
    width: 95%;
    height: 3px;
    background: repeating-linear-gradient(
        to right,
        #6B7280 0 10px,
        transparent 10px 22px
    );
    opacity: 0.6;
    z-index: 1;
    transform: translateY(-50%);
}

.progress-bubble {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 90px;
    height: 45px;
    background-color: #4c7dc3;
    background-image: url('assets/images/Car.png');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    border: 2px solid var(--text-light);
    border-radius: 5px 15px 15px 5px;
    box-shadow: 4px 6px 10px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: var(--text-light);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    transition: left 0.5s ease;
    z-index: 4;
}

.progress-bubble.no-anim {
    transition: none !important;
}

.progress-bubble.arrival {
    background-color: #0d7787 !important;
    border-color: #E1ED76 !important;
    color: #fff !important;
    box-shadow: 0 0 4px 4px rgba(225,237,118,0.5);
    filter: drop-shadow(0 0 8px #0e8b3c);
    animation: arrival-glow 1.2s ease-in-out infinite alternate;
}

.progress-arrival-flag {
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-color: white;
    z-index: 3;
}

/* ========================================
   MINI BARRES DES AUTRES JOUEURS
   ======================================== */

/* Piste mini : ligne blanche 2px, outline gris 2px */
.mini-progress-track {
    background-color: #ffffff;
    height: 6px;
    border: 2px solid #D4D4D4;
    border-radius: 4px;
    position: relative;
    overflow: visible;
    /* pas de pointillés */
}

/* Marqueur des autres joueurs : bloc 6px de hauteur, même largeur que .progress-bubble (90px) */
.mini-progress-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 90px;
    height: 10px;
    background-color: #7EA5BF;
    border: 2px solid var(--text-light);
    border-radius: 5px;
    box-shadow: 4px 6px 10px rgba(0, 0, 0, 0.4);
    transition: left 0.5s ease;
    z-index: 4;
}

.mini-progress-marker.arrival {
    border-color: #E1ED76;
    box-shadow: 0 0 2px 2px rgba(225,237,118,0.3);
}


/* ========================================
   GAME CONTAINERS
   ======================================== */
.game-containers-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    margin: 10px 10px 50px 10px;
    /* Optimisations hardware acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

.game-containers {
    display: flex;
    width: 400%; /* 4 joueurs max */
    height: 100%;
    gap: 20px;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.game-containers.animating {
    pointer-events: none;
    z-index: 10;
}

/* Animations de slide pour changement de joueur */
.game-containers.slide-to-player-0 { transform: translateX(0); }
.game-containers.slide-to-player-1 { transform: translateX(calc(-25% - 20px)); }
.game-containers.slide-to-player-2 { transform: translateX(calc(-50% - 40px)); }
.game-containers.slide-to-player-3 { transform: translateX(calc(-75% - 60px)); }

.game-container {
    flex: 0 0 25%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border-radius: 24px 24px 12px 12px;
    background-color: var(--card-bg2);
}

/* ========================================
   GAME BOARD
   ======================================== */
.game-board-slider {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
}

.game-board {
    flex: 1 1 0;
    min-height: 0;
    border-top: #333 solid 2px;
    background-color: var(--bg-board);
    box-shadow: inset 0 14px 8px -8px rgba(0, 0, 0, 0.2);
    padding: 16px 0px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: stretch;
    transition: transform 0.5s cubic-bezier(.77,0,.18,1);
    will-change: transform;
}

.card-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 0;
    min-height: 0;
}

/* ========================================
   CONTROLES ET BOUTONS
   ======================================== */
.controls-left {
    display: flex;
    align-items: center;
    padding: 4px 4px 4px 12px;
    flex-shrink: 0;
}

.controls {
    display: flex;
    align-items: center;
    border-radius: 20px 0px 0px 20px;
    background-color: var(--card-bg);
    box-shadow: #00000050 0px 2px 8px;
    padding: 5px 8px 5px 5px;
    flex-shrink: 0;
}

.controls .count {
    color: var(--bg-dark-grey);
    font-weight: bold;
    font-size: 16px;
    min-width: 33px;
    text-align: center;
}

/* Boutons de rangée (+ et -) */
.card-row-btn {
    background: transparent;
    border: 2px solid var(--danger-red);
    color: var(--danger-red);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
}

.card-row-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.card-row-btn.add {
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

.card-row-btn.add:disabled {
    border-color: var(--primary-blue);
    color: var(--primary-blue);
    opacity: 0.3;
    cursor: not-allowed;
}

/* Bouton icône générique */
.icon-btn {
    background: var(--primary-blue);
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: var(--primary-blue-hover);
}

.icon-btn img {
    width: 22px;
    height: 22px;
    filter: invert(1) brightness(2);
}

/* ========================================
   CARTES ET PLACEHOLDERS
   ======================================== */
.card-track {
    flex: 1 1 0;
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-start;
    align-items: center;
    min-height: 0;
    padding: 20px 0;
    height: 100%;
    position: relative;
}

.placeholders-container,
.cards-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-start;
    align-items: center;
    padding: 6px 0;
}

.placeholders-container {
    z-index: 1;
}

.cards-container {
    z-index: 2;
    pointer-events: none;
}

/* Éléments de carte communs */
.card,
.card-placeholder,
.card-slot {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: 100%;
    max-height: 300px;
    border-radius: 8px;
    transition: none;
    position: relative;
    box-sizing: border-box;
    flex-basis: 0;
    flex-grow: 1;
    flex-shrink: 1;
}

.card {
    background: linear-gradient(20deg, #E1ED76 40%, #EBF4FD 43%, #EBF4FD 70%, #E1ED76 73%);
    border: 4px solid var(--card-bg);
    box-shadow: 3px 2px 4px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 3px;
    z-index: 2;
}

.card-placeholder {
    border: 2px dashed var(--card-placeholder-border);
    background: var(--card-placeholder-bg);
    z-index: 1;
    overflow: hidden;
}

.card-slot {
    opacity: 0;
    transition: opacity 0.2s ease;
    container-type: size;
}

.card-slot .card {
    width: 100%;
    height: 100%;
}

/* Images dans les cartes */
/* Images dans les cartes (optimisé) */
.card img,
.card-placeholder img {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    user-select: none;
}

.card .km-value {
    left: 45%;
    top: 60%;
    height: 80%;
    z-index: 1;
    max-height: 80%;
    max-width: 80%;
    filter: drop-shadow(-1.5px -1.5px 0.2px white) drop-shadow(1.5px -1.5px 0.2px white) drop-shadow(-1.5px 1.5px 0.2px white) drop-shadow(1.5px 1.5px 0.2px white);
}

.card .animal {
    right: -10%;
    top: -10%;
    left: auto;
    transform: none;
    width: 85%;
    height: 85%;
    object-fit: contain;
    z-index: 0;
}

.card-placeholder .km-bg {
    left: 50%;
    top: 50%;
    width: 70%;
    opacity: 0.3;
    z-index: 0;
    max-height: 80%;
    max-width: 80%;
}

/* Masquer illustration sauf première carte */
.card-placeholder:not(:nth-child(1)) img.km-bg {
    display: none;
}

/* Z-index pour ordre d'empilement des placeholders */
.placeholders-container .card-placeholder:nth-child(1) { z-index: 10; }
.placeholders-container .card-placeholder:nth-child(2) { z-index: 9; }
.placeholders-container .card-placeholder:nth-child(3) { z-index: 8; }
.placeholders-container .card-placeholder:nth-child(4) { z-index: 7; }
.placeholders-container .card-placeholder:nth-child(5) { z-index: 6; }
.placeholders-container .card-placeholder:nth-child(6) { z-index: 5; }
.placeholders-container .card-placeholder:nth-child(7) { z-index: 4; }
.placeholders-container .card-placeholder:nth-child(8) { z-index: 3; }
.placeholders-container .card-placeholder:nth-child(9) { z-index: 2; }
.placeholders-container .card-placeholder:nth-child(10) { z-index: 1; }

/* Z-index pour les cartes (dernière posée au-dessus) */
.cards-container .card-slot:nth-child(1) { z-index: 11; }
.cards-container .card-slot:nth-child(2) { z-index: 12; }
.cards-container .card-slot:nth-child(3) { z-index: 13; }
.cards-container .card-slot:nth-child(4) { z-index: 14; }
.cards-container .card-slot:nth-child(5) { z-index: 15; }
.cards-container .card-slot:nth-child(6) { z-index: 16; }
.cards-container .card-slot:nth-child(7) { z-index: 17; }
.cards-container .card-slot:nth-child(8) { z-index: 18; }
.cards-container .card-slot:nth-child(9) { z-index: 19; }
.cards-container .card-slot:nth-child(10) { z-index: 20; }

/* Marges pour superposition (sélecteurs optimisés) */
.card:not(:first-child),
.card-placeholder:not(:first-child),
.card-slot:not(:first-child) {
    margin-right: calc(-1 * min(40px, 4vw));
}

/* ========================================
   MODAL
   ======================================== */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--card-bg);
    color: var(--text-dark);
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 350px;
}

.modal-content h3 {
    font-size: 20px;
    margin-bottom: 16px;
}

.modal-content p {
    color: #6B7280;
    margin-bottom: 24px;
}

.player-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 16px;
    border-bottom: 1px solid #E5E7EB;
}

.modal-content h3.player-modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.count-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.count-btn.remove {
    background: transparent;
    color: var(--danger-red);
    border: 1px solid var(--danger-red);
}

.count-btn.add {
    background: transparent;
    color: var(--primary-blue);
    border: 1px solid var(--primary-blue);
}

.count-btn:disabled,
.count-btn:disabled:hover {
    background: #EEEEEE;
    color: #BBBBBB;
    border-color: #EEEEEE;
    cursor: default;
}

.modal-content .player-name-inputs {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 16px 0;
    border-bottom: 1px solid #E5E7EB;
    margin-bottom: 16px;
    /* Hauteur fixe pour 4 joueurs : les boutons +/- ne bougent pas */
    min-height: calc(4 * 42px + 3 * 12px + 32px);
    box-sizing: border-box;
}

.player-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
}

.player-name-row.dragging {
    position: relative;
    z-index: 1;
    opacity: 0.9;
}

.player-name-row.dragging input {
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.drag-handle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 20px;
    height: 40px;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
}

.drag-handle span {
    display: block;
    height: 3px;
    border-radius: 2px;
    background: #BBBBBB;
}

.player-name-row.dragging .drag-handle {
    cursor: grabbing;
}

.modal-content .player-name-inputs input {
    flex: 1;
    min-width: 0;
    height: 42px;
    box-sizing: border-box;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    padding: 10px;
    font-size: 16px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-buttons.spread {
    justify-content: space-between;
}

.modal-btn {
    border: 1px solid #D1D5DB;
    background-color: var(--card-bg);
    color: var(--text-dark);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

.modal-btn.primary {
    background-color: var(--primary-blue);
    color: var(--text-light);
    border-color: var(--primary-blue);
}

/* ========================================
   BOUTONS DANGER/RESET - STYLES UNIFIÉS
   ======================================== */
.btn-danger,
.btn-alert,
.modal-btn.alert {
    background: var(--danger-red);
    color: var(--text-light);
    border: 2px solid var(--danger-red-hover);
    border-radius: 8px;
    font-weight: bold;
    transition: background 0.2s, color 0.2s;
}

.btn-danger:hover,
.btn-alert:hover,
.modal-btn.alert:hover {
    background: var(--danger-red-hover);
    color: #fff;
}

.modal-btn.secondary.alert {
    background-color: transparent;
    color: var(--danger-red);
    border: 1px solid var(--danger-red);
}

.modal-btn.secondary.alert:hover {
    background-color: var(--danger-red);
    color: var(--text-light);
    border-color: var(--danger-red-hover);
}

#reset-btn {
    background: transparent;
    color: var(--danger-red);
    border: 1px solid var(--danger-red);
    border-radius: 8px;
    font-weight: bold;
    transition: background 0.2s, color 0.2s;
}

#reset-btn:hover {
    background: var(--danger-red);
    color: #fff;
    border-color: var(--danger-red-hover);
}

#reset-btn img,
#reset-btn svg {
    color: var(--danger-red);
    fill: var(--danger-red);
    width: 20px;
    height: 20px;
    transition: color 0.2s, fill 0.2s;
}

#reset-btn:hover img,
#reset-btn:hover svg {
    color: #fff;
    fill: #fff;
}

/* ========================================
   FOOTER & NAVIGATION
   ======================================== */
.player-nav {
    display: none;
    flex-shrink: 0;
    background-color: var(--bg-dark);
    justify-content: space-between;
    align-items: center;
}

.nav-arrow {
    background: var(--primary-blue);
    border: var(--primary-blue);
    opacity: 0.9;
    border-radius: 20%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.nav-arrow:disabled {
    background-color: none;
    cursor: not-allowed;
}

.nav-arrow img {
    width: 20px;
    height: 20px;
    fill: #1D4ED8;
}

.current-player-info {
    color: var(--bg-board);
    font-size: 24px;
    font-weight: 600;
}

/* ========================================
   RÈGLES SPÉCIALES
   ======================================== */
/* Masquer placeholders pour cartes 200km (première rangée) */
.card-row:first-child .placeholders-container .card-placeholder:nth-child(n+3) {
    visibility: hidden;
}