/* ==========================================================================
   Le Grand Prix des Losers — feuille de style
   Theme : piste de course nocturne, accents orange/jaune, damier de course.
   Mobile-first, boutons >= 44px, texte >= 16px, sans framework externe.
   ========================================================================== */

:root {
    --bg-night: #0c1524;
    --bg-panel: #142238;
    --bg-panel-light: #1c3050;
    --border-soft: #2a4266;
    --accent-orange: #f5a623;
    --accent-yellow: #ffd60a;
    --accent-red: #e5484d;
    --accent-green: #4caf6a;
    --text-main: #eef2fa;
    --text-muted: #93a3c2;
    --radius: 14px;
    --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.35);
    --tap-min: 48px;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    height: 100%;
}

body {
    margin: 0;
    height: 100vh;
    height: 100dvh; /* tient compte des barres d'adresse mobiles qui vont et viennent */
    overflow: hidden; /* pas de scroll de page : chaque ecran gere son propre debordement */
    font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    color: var(--text-main);
    background:
        radial-gradient(circle at 50% -10%, #1c3050 0%, var(--bg-night) 55%);
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 520px;
    height: 100%;
    margin: 0 auto;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Bandeau damier decoratif -------------------------------------------- */
.checker-strip {
    flex-shrink: 0;
    height: 6px;
    border-radius: 3px;
    margin-bottom: 8px;
    background-image: repeating-linear-gradient(
        45deg,
        #0c1524 0 10px,
        #eef2fa 10px 20px
    );
    opacity: 0.85;
}

/* --- Ecrans -----------------------------------------------------------------
   Chaque ecran occupe tout l'espace restant sous le damier, en colonne flex.
   Ses enfants gardent leur taille naturelle SAUF celui marque
   .screen-scroll-area, qui absorbe l'espace restant et defile en interne si
   son contenu est trop grand — ainsi l'en-tete, les cartes d'info et les
   boutons d'action restent toujours visibles sans avoir a scroller la page. */
.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    /* Filet de securite : si un ecran sans .screen-scroll-area deborde quand
       meme (petit telephone, texte agrandi...), il defile lui-meme plutot
       que de couper du contenu invisible en bas. */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: fade-in 0.25s ease;
}

.screen.active {
    display: flex;
}

.screen-scroll-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Typo ------------------------------------------------------------------ */
h1, h2, h3 {
    margin: 0 0 8px;
    line-height: 1.2;
}

h1 {
    font-size: 1.4rem;
    letter-spacing: 0.5px;
}

h2 {
    font-size: 1.1rem;
    color: var(--accent-yellow);
}

p {
    margin: 0 0 8px;
    color: var(--text-muted);
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-size: 0.85rem;
}

/* --- Logo / hero ------------------------------------------------------------ */
.hero-banner {
    display: block;
    width: 100%;
    max-height: 22vh;
    object-fit: cover;
    object-position: center 35%;
    height: auto;
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow-card);
    flex-shrink: 0;
}

/* --- Cartes / panneaux ------------------------------------------------------ */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-card);
}

.card-compact {
    padding: 10px 16px;
    margin-bottom: 12px;
}

.card-compact .stat-row {
    padding: 6px 0;
}

.billets-summary {
    margin: 0;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.billets-summary span {
    font-weight: 800;
    color: var(--accent-yellow);
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.card-header-row h2 {
    margin-bottom: 0;
}

.card-header-row .btn-small {
    width: auto;
    flex-shrink: 0;
}

/* Boutons cote a cote (ex: actions bookmaker Case 5 / Saisir le podium +
   Tour suivant) pour gagner de la place en hauteur. Priorite forte (ID) pour
   annuler width:100% et le margin-top de "button + button". */
#pd-bookmaker-actions.button-row {
    display: flex;
    gap: 10px;
}

#pd-bookmaker-actions.button-row > button {
    width: auto;
    flex: 1;
    margin-top: 0;
}

/* --- Boutons ----------------------------------------------------------------- */
button {
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    border-radius: 10px;
    min-height: var(--tap-min);
    padding: 12px 18px;
    transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}

button:active {
    transform: scale(0.97);
}

/* Espace les boutons empiles verticalement (actions bookmaker, boutons pleine
   largeur d'un ecran...). Sans effet sur les groupes de boutons en ligne
   (billet-actions, card-header-row) car un span s'y intercale toujours entre
   deux boutons, donc le combinateur "+" adjacent ne s'y applique jamais. */
button + button {
    margin-top: 10px;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(180deg, var(--accent-orange), #d9860f);
    color: #1a1200;
    font-weight: 700;
    box-shadow: 0 4px 0 #a86608;
}

.btn-primary:active:not(:disabled) {
    box-shadow: 0 2px 0 #a86608;
}

.btn-secondary {
    width: 100%;
    background: var(--bg-panel-light);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
}

.btn-danger {
    width: 100%;
    background: linear-gradient(180deg, var(--accent-red), #b8302f);
    color: #fff;
    font-weight: 700;
}

.btn-small {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.9rem;
}

.btn-block + .btn-block {
    margin-top: 10px;
}

/* --- Champs de formulaire ------------------------------------------------------ */
label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

input[type="text"] {
    width: 100%;
    font-size: 1rem;
    padding: 10px 14px;
    min-height: var(--tap-min);
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    background: var(--bg-night);
    color: var(--text-main);
    margin-bottom: 8px;
}

input[type="text"]:focus {
    outline: 2px solid var(--accent-orange);
    outline-offset: 1px;
}

input.code-input {
    text-transform: uppercase;
    letter-spacing: 6px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
}

/* --- Code de partie affiche en grand -------------------------------------------- */
.game-code-display {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 8px;
    color: var(--accent-yellow);
    background: var(--bg-night);
    border: 2px dashed var(--accent-orange);
    border-radius: var(--radius);
    padding: 10px 8px;
    margin-bottom: 4px;
    word-break: break-all;
}

/* --- Liste de joueurs --------------------------------------------------------- */
.player-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.player-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-panel-light);
    border-radius: 10px;
    margin-bottom: 6px;
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-green);
    flex-shrink: 0;
}

.player-list .you-tag {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--accent-yellow);
    font-weight: 700;
}

/* --- Bannieres d'etat -------------------------------------------------------- */
.banner {
    flex-shrink: 0;
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 8px;
    font-weight: 700;
    text-align: center;
}

.banner-bookmaker {
    background: linear-gradient(180deg, #3a2b12, #2a1f0d);
    border: 1px solid var(--accent-orange);
    color: var(--accent-yellow);
}

.banner-turn {
    background: linear-gradient(180deg, #123a2a, #0d2a1f);
    border: 1px solid var(--accent-green);
    color: #a8f5c4;
}

.banner-wait {
    background: var(--bg-panel-light);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
}

.banner-alert {
    background: linear-gradient(180deg, #4a1414, #2e0d0d);
    border: 1px solid var(--accent-red);
    color: #ffb3b3;
    animation: pulse-alert 1.4s ease-in-out infinite;
}

@keyframes pulse-alert {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.25); }
}

.banner-warning-perso {
    background: #3a2b12;
    border: 1px solid var(--accent-yellow);
    color: var(--accent-yellow);
}

/* Bandeau explicatif (rappel de regle), volontairement moins alarmant qu'une
   alerte : texte aligne a gauche, poids normal, pas d'animation. */
.banner-info {
    background: linear-gradient(180deg, #12283a, #0d1f2a);
    border: 1px solid #3a8fc7;
    color: #a8d8f5;
    font-weight: 500;
    text-align: left;
    line-height: 1.4;
    font-size: 0.9rem;
}

/* --- Tableau des cotes --------------------------------------------------------- */
.cotes-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 4px;
}

.cote-row {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 8px;
    align-items: center;
    background: var(--bg-panel-light);
    border-radius: 12px;
    padding: 7px 10px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, opacity 0.2s ease;
}

.cote-row.selected {
    border-color: var(--accent-orange);
}

.cote-row.full {
    opacity: 0.5;
}

.cote-emoji {
    font-size: 1.4rem;
    text-align: center;
}

.cote-name {
    font-weight: 700;
    margin-bottom: 2px;
    font-size: 0.95rem;
}

.cote-slots {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cote-slot {
    font-size: 0.78rem;
    padding: 3px 8px;
    border-radius: 20px;
    background: var(--bg-night);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    white-space: nowrap;
}

.cote-slot.taken {
    color: var(--bg-night);
    font-weight: 700;
    border-color: transparent;
}

/* Nos propres paris ressortent en jaune ; ceux des autres joueurs dans un
   bleu neutre — jamais rouge, couleur reservee aux alertes du jeu. */
.cote-slot.taken.mine {
    background: var(--accent-yellow);
    color: #2a1f00;
}

.cote-slot.taken.other {
    background: #3a5a8a;
    color: #eef2fa;
}

.cote-row button.pick-btn {
    margin-top: 6px;
    width: 100%;
}

.billet-counter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}

.billet-count-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent-yellow);
    min-width: 24px;
    text-align: center;
}

.billet-actions {
    display: flex;
    gap: 8px;
    flex: 1;
}

.billet-actions button {
    flex: 1;
}

/* --- Infos joueur / billets ---------------------------------------------------- */
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-soft);
}

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

.stat-label {
    color: var(--text-muted);
}

.stat-value {
    font-weight: 700;
    color: var(--accent-yellow);
}

/* --- Podium / fin de course ------------------------------------------------------ */
.podium-drop-zone {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.podium-slot {
    flex: 1;
    min-height: 64px;
    border: 2px dashed var(--border-soft);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--bg-panel-light);
    transition: border-color 0.2s ease, background 0.2s ease;
}

.podium-slot.filled {
    border-style: solid;
    border-color: var(--accent-orange);
}

.podium-slot.drag-over {
    border-color: var(--accent-yellow);
    background: var(--bg-night);
}

.podium-slot .slot-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.perso-pool {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.perso-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 7px 12px;
    background: var(--bg-panel-light);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    cursor: grab;
    user-select: none;
    touch-action: none;
    min-width: 56px;
}

.perso-chip.placed {
    opacity: 0.3;
    cursor: not-allowed;
}

.perso-chip.selected {
    border-color: var(--accent-yellow);
    box-shadow: 0 0 0 2px var(--accent-yellow);
}

.perso-chip .cote-emoji {
    font-size: 1.9rem;
}

.perso-chip .perso-label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.results-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.results-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg-panel-light);
    border-radius: 10px;
    margin-bottom: 6px;
}

.results-list .gain-positive {
    color: var(--accent-green);
    font-weight: 700;
}

.results-list .gain-zero {
    color: var(--text-muted);
}

/* Variante compacte utilisee pour re-afficher les paris faits (Phase E),
   en plus petit que les listes de gains/scores principales. */
.results-list-small li {
    padding: 6px 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Classement final --------------------------------------------------------- */
.ranking-list {
    list-style: none;
    padding: 0;
    margin: 0 0 10px;
    counter-reset: rank;
}

.ranking-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-panel-light);
    border-radius: 12px;
    margin-bottom: 8px;
}

.ranking-list li.winner {
    background: linear-gradient(180deg, #3a2b12, #241b0c);
    border: 1px solid var(--accent-yellow);
}

.rank-number {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent-orange);
    min-width: 28px;
}

.ranking-list li.winner .rank-number {
    color: var(--accent-yellow);
}

.rank-name {
    flex: 1;
    font-weight: 700;
}

.rank-score {
    font-weight: 800;
    color: var(--accent-yellow);
}

.trophy {
    font-size: 1.4rem;
}

/* --- Barre d'infos partie (code + quitter) --------------------------------------
   Le numero de course/tour et l'etape en cours ne sont plus affiches ici
   (juges superflus) : il ne reste que le code de partie et le bouton "Quitter". */
.game-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-bottom: 8px;
}

.game-header .code-chip,
.game-header .course-chip {
    flex-shrink: 0;
    background: var(--bg-panel-light);
    border-radius: 20px;
    padding: 4px 10px;
    letter-spacing: 1.5px;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--accent-yellow);
}

.game-header .course-chip {
    color: var(--text-muted);
    letter-spacing: normal;
}

/* Pousse le bouton Quitter tout a droite ; le(s) badge(s) restent groupes a gauche. */
.btn-leave-game {
    flex-shrink: 0;
    margin-left: auto;
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 1.1rem;
    background: transparent;
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    border-radius: 50%;
}

.btn-leave-game:active {
    background: var(--bg-panel-light);
}

/* --- Toast d'erreur -------------------------------------------------------------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%) translateY(20px);
    background: var(--accent-red);
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-weight: 600;
    box-shadow: var(--shadow-card);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 100;
    max-width: 90vw;
    text-align: center;
}

#toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* --- Utilitaires ----------------------------------------------------------------- */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-16 {
    margin-top: 16px;
}

.small-muted {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid var(--border-soft);
    border-top-color: var(--accent-orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.waiting-block {
    text-align: center;
    padding: 24px 12px;
}

/* --- Media : ecrans un peu plus larges (tablette) --------------------------------- */
@media (min-width: 560px) {
    #app {
        padding-top: 32px;
    }

    .podium-drop-zone {
        gap: 20px;
    }
}
