/* ===== Défi Km – écran d'affichage ===== */
:root {
    --primary: #E61C51;
    --accent: #FF8216;
    --ink: #1f2430;
    --muted: #4a5160;
    --card: rgba(236, 246, 252, .88);
    --card-strong: rgba(214, 236, 247, .95);
    --shadow: 0 10px 28px rgba(0, 0, 0, .18);
    --font: 'Poppins', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body.display { margin: 0; height: 100%; overflow: hidden; background: #1a1a1a; font-family: var(--font); color: var(--ink); }

.screen { position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; background: #a9d8ee; }

/* ---------- Scène (décor + cyclistes) ---------- */
.viewport { position: absolute; inset: 0; overflow: hidden; overflow: clip; overflow-anchor: none; touch-action: none; cursor: grab; user-select: none; }
/* overflow: clip : la zone n'est jamais « défilable », même quand la scène agrandie (mode net Safari) la dépasse */
/* Pas de sélection ni de surbrillance bleue quand on clique / glisse sur le décor (Safari a besoin des versions -webkit-) */
.viewport, .viewport * {
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.viewport img { -webkit-user-drag: none; user-drag: none; }
.viewport.dragging { cursor: grabbing; }
.viewport.locked { cursor: default; }
.scene { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.scene.animate, .viewport.dragging .scene { will-change: transform; } /* seulement pendant les mouvements : sinon Safari garde une image basse résolution */
.scene.animate { transition: transform .8s cubic-bezier(.25, .8, .25, 1); }
.scene.no-anim, .scene.no-anim .rider, .scene.no-anim .rider .tag { transition: none !important; }
.decor { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.rider { position: absolute; transform: translate(-92%, -100%); /* l'avant du vélo est sur son km : personne ne dépasse la ligne de départ à 0 km */ transition: left .9s ease-out, top .9s ease-out; cursor: pointer; }
.rider .tag { transition: margin-bottom .25s ease-out; } /* repositionnement doux des étiquettes */
.rider.dup-tag .tag { display: none; }                   /* même km qu'un voisin : une seule étiquette */
.rider.dup-tag:hover .tag, .rider.dup-tag.selected .tag { display: block; z-index: 5; }
.rider img { display: block; height: 100%; width: auto; margin: 0 auto; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .45)); pointer-events: none; }
.rider .tag {
    position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); margin-bottom: 2px;
    background: rgba(255, 255, 255, .85); color: #000; border-radius: 4px; padding: 1px 4px;
    font-weight: 700; line-height: 1.15; white-space: nowrap; text-align: center; pointer-events: none;
    border-left: .35em solid #999; /* couleur de l'équipe : on sait à qui est l'étiquette */
}
.rider .tag small { display: block; font-weight: 600; color: var(--primary); }
.rider.leader .tag { background: var(--primary); color: #fff; }
.rider.leader .tag small { color: #fff; }
.rider.selected img { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 12px var(--primary)); }

.flag { position: absolute; transform: translate(-50%, -100%); pointer-events: none; text-align: center; }
.flag .pole { width: 1.5px; margin: 0 auto; background: rgba(40, 40, 40, .7); }
.flag .cloth {
    background: var(--primary); color: #fff; font-weight: 800; border-radius: 3px; padding: 1px 4px;
    white-space: nowrap; box-shadow: 0 2px 4px rgba(0, 0, 0, .3); line-height: 1.2;
}
.flag.reached .cloth { background: #1f9d55; }

/* bulle « Débloquez-moi » : la gauche du haut-parleur est sur le km de la prochaine info,
   la bulle est au-dessus et à droite du pavillon (c'est le haut-parleur qui parle) */
.callout { position: absolute; transform: translate(0, -100%); pointer-events: none; }
.callout .bubble { display: block; width: 100%; }
.callout .speaker { position: absolute; left: -30%; bottom: -36%; width: 38%; } /* % = de la bulle */
.callout.attention .bubble { animation: bubblePulse 2.6s ease-in-out; }
.callout.attention .speaker { animation: speakerBounce 2.6s ease-in-out; }
@keyframes bubblePulse { 0%, 100% { transform: scale(1) } 15% { transform: scale(1.1) } 38% { transform: scale(.97) } 62% { transform: scale(1.05) } }
@keyframes speakerBounce { 0%, 100% { transform: rotate(0) } 15% { transform: translateY(-3px) rotate(-8deg) } 30% { transform: rotate(6deg) } 46% { transform: translateY(-2px) rotate(-4deg) } }

.fog {
    position: absolute; top: 0; bottom: 0; z-index: 400; pointer-events: none;
    background: linear-gradient(90deg, rgba(221, 240, 250, 0) 0, rgba(221, 240, 250, .92) 160px, rgba(221, 240, 250, .97) 100%);
    backdrop-filter: blur(2px);
}
.fog span { position: absolute; left: 70px; font-weight: 800; color: var(--primary); white-space: nowrap; opacity: .85; }

/* ---------- Bandeau du haut ---------- */
.hud-top {
    position: absolute; top: 16px; left: 24px; right: 24px; z-index: 10; pointer-events: none;
    display: grid; gap: 20px; align-items: start;
    grid-template-columns: minmax(120px, 200px) minmax(240px, 380px) minmax(280px, 440px) minmax(110px, 180px);
    justify-content: space-between;
}
.hud-top > * { pointer-events: auto; }
/* logos en image de fond d'une boîte de hauteur fixe : rendu identique dans tous les navigateurs */
.logo-box { height: 100px; background: left center / contain no-repeat; }
.logo-box[hidden] { display: block; visibility: hidden; }
.logo-bnl { background-position: right center; }

.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(3px); }
.card h2 {
    margin: 0 0 6px; text-align: center; text-transform: uppercase; color: var(--primary);
    font-size: clamp(13px, 1.25vw, 22px); font-weight: 800; letter-spacing: .02em; line-height: 1.1;
}

.goal { padding: 10px 16px 12px; }
.goal-value { display: flex; justify-content: center; align-items: baseline; gap: 8px; font-weight: 800; line-height: 1; margin-bottom: 8px; }
.goal-value .cur { color: var(--primary); font-size: clamp(22px, 2.6vw, 42px); }
.goal-value .tot { color: #3c3c3c; font-size: clamp(16px, 1.9vw, 30px); }
.goal-track { height: clamp(10px, 1vw, 16px); background: #bfe7f4; border-radius: 999px; overflow: hidden; }
.goal-progress { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--primary)); transition: width 1.2s ease; }
.milestones { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: clamp(11px, .95vw, 16px); }
.milestones li { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.milestones li b { color: var(--primary); }
.milestones li.reached b::after { content: ' ✓'; color: #1f9d55; }

.board { padding: 10px 12px 12px; }
.board ol {
    list-style: none; margin: 0; padding: 2px 4px 2px 2px; max-height: 64vh; overflow-y: auto; scroll-behavior: smooth;
    scrollbar-width: thin; scrollbar-color: var(--primary) transparent; overscroll-behavior: contain;
}
.board ol::-webkit-scrollbar { width: 6px; }
.board ol::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
.board li {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
    margin-bottom: 6px; padding: 3px 8px 3px 3px; background: var(--card-strong); border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .12); font-size: clamp(11px, .95vw, 16px); cursor: pointer;
}
.board li.first { background: #fff; outline: 2px solid var(--primary); }
.board .rank { font-weight: 800; color: var(--primary); min-width: 1.6em; text-align: center; }
.board .swatch { width: 34px; height: 34px; border-radius: 5px; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.board .swatch img { max-width: 26px; max-height: 26px; }
.board .name { font-weight: 700; overflow: hidden; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.board .km { text-align: right; white-space: nowrap; font-weight: 700; }
.board .km small { display: block; font-weight: 400; color: var(--muted); font-size: .78em; }
.board .empty { text-align: center; margin: 4px 0; }
.board-sub { text-align: center; font-size: clamp(10px, .8vw, 13px); color: var(--muted); margin: -4px 0 6px; }

/* Classement compact (réglage du challenge) */
.screen.board-compact .hud-top { grid-template-columns: minmax(120px, 200px) minmax(240px, 380px) minmax(200px, 290px) minmax(110px, 180px); }
.board-compact .board { padding: 8px 10px 8px; }
.board-compact .board li { margin-bottom: 3px; padding: 1px 6px 1px 2px; font-size: clamp(11px, .8vw, 14px); gap: 6px; }
.board-compact .board .swatch { width: 24px; height: 24px; }
.board-compact .board .swatch img { max-width: 18px; max-height: 18px; }

/* ---------- Bandeau du bas ---------- */
.hud-bottom {
    position: absolute; left: 18px; right: 18px; bottom: 18px; z-index: 10;
    display: flex; gap: 14px; align-items: stretch; pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.phrase { flex: 1 1 auto; display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: #fff; border-radius: 10px; font-size: clamp(13px, 1.1vw, 20px); line-height: 1.35; }
.phrase img { width: clamp(28px, 3vw, 46px); flex: 0 0 auto; }
.phrase .title { color: var(--primary); font-weight: 800; margin-bottom: 2px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.phrase-body { flex: 1 1 auto; min-width: 0; }
.phrase-nav { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8em; font-weight: 600; }
.phrase-nav button {
    width: 1.7em; height: 1.7em; border: 0; border-radius: 50%; background: var(--primary); color: #fff;
    font: inherit; font-size: 1.25em; font-weight: 800; line-height: 1; padding: 0 0 .12em; cursor: pointer; display: grid; place-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .2); padding: 0;
}
.phrase-nav button:hover:not(:disabled) { filter: brightness(1.1); transform: scale(1.08); }
.phrase-nav button:disabled { background: #d0d5dd; box-shadow: none; cursor: default; }
.phrase .next { color: var(--muted); font-size: .8em; margin-top: 2px; }
.equiv { flex: 0 1 380px; padding: 10px 16px; background: #fff; border-radius: 10px; font-size: clamp(12px, 1vw, 18px); line-height: 1.35; }
.equiv .title { color: var(--primary); font-weight: 800; margin-bottom: 2px; }
.equiv .route { font-weight: 700; }
.equiv .next { color: var(--muted); font-size: .85em; margin-top: 2px; }

.closed-banner {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 12;
    background: var(--primary); color: #fff; font-weight: 800; padding: 12px 26px; border-radius: 12px;
    font-size: clamp(16px, 2vw, 30px); box-shadow: var(--shadow); pointer-events: none; text-align: center;
}

.draft-banner {
    position: absolute; left: 50%; top: 0; transform: translateX(-50%); z-index: 20;
    background: #fffaeb; color: #b54708; border: 1px solid #fedf89; border-top: 0; border-radius: 0 0 10px 10px;
    padding: 6px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 4px 12px rgba(0, 0, 0, .12); max-width: calc(100vw - 20px);
}
.draft-banner a { color: var(--primary); margin-left: 6px; }

/* ---------- Navigation ---------- */
.nav-controls { position: absolute; right: 18px; bottom: 50%; transform: translateY(50%); z-index: 11; display: grid; gap: 6px; opacity: .35; transition: opacity .3s; }
.nav-controls:hover, .screen.interacting .nav-controls { opacity: 1; }
.nav-controls button {
    width: 42px; height: 42px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .92);
    color: var(--ink); font-size: 22px; font-weight: 700; cursor: pointer; box-shadow: 0 3px 10px rgba(0, 0, 0, .2);
}
.nav-controls button:hover { background: var(--primary); color: #fff; }

/* ---------- Fiche équipe ---------- */
.team-card { position: absolute; z-index: 13; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100vw - 32px)); padding: 18px 20px; background: #fff; }
.team-card h3 { margin: 0 0 4px; font-size: 22px; }
.team-card .close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.team-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 12px 0; }
.team-card dt { color: var(--muted); }
.team-card dd { margin: 0; font-weight: 700; text-align: right; }
.team-card .route { background: #f2f8fc; border-radius: 8px; padding: 8px 10px; }

/* ---------- Démo ---------- */
.demo-bar { position: absolute; left: 0; bottom: calc(100% + 10px); padding: 8px 10px; display: grid; grid-auto-flow: column; align-items: center; gap: 6px; background: #fff; font-size: 14px; width: auto; }
.demo-bar button, .demo-bar a { white-space: nowrap; }
.demo-bar strong { color: var(--primary); text-transform: uppercase; font-size: 12px; }
.demo-bar button, .demo-bar a {
    display: block; border: 0; border-radius: 8px; padding: 8px 10px; font: inherit; font-weight: 600; text-align: left;
    background: #eef6fb; color: var(--ink); cursor: pointer; text-decoration: none;
}
.demo-bar button:not(:disabled):hover, .demo-bar a:hover { background: var(--primary); color: #fff; }
.demo-bar button:disabled { cursor: wait; }
.demo-bar button:disabled:not(.waiting) { opacity: .55; }
/* Jauge d'attente qui se remplit dans le bouton cliqué */
.demo-bar button.waiting {
    background-image: linear-gradient(rgba(230, 28, 81, .3), rgba(230, 28, 81, .3));
    background-repeat: no-repeat; background-size: 0% 100%;
    animation: demoWait var(--wait, 2.5s) linear forwards;
}
@keyframes demoWait { to { background-size: 100% 100%; } }

/* ---------- Éléments repliables (petits écrans) ---------- */
.board.collapsed li:nth-child(n+4) { display: none; }
.board-toggle { display: block; width: 100%; margin-top: 2px; border: 0; background: none; color: var(--primary); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; padding: 2px; }
.phrase { cursor: default; }

/* ---------- Tablettes (portrait) et petits portables ---------- */
@media (max-width: 1000px) {
    .hud-top { top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px; gap: 8px; grid-template-columns: minmax(70px, .5fr) minmax(0, 1.5fr); }
    .logo-bnl { display: none; }
    .logo-box { height: 60px; }
    .board { grid-column: 1 / -1; }
    .board ol { max-height: 50vh; overflow-y: auto; }
    .board li { font-size: 13px; }
    .hud-bottom { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); flex-direction: column; gap: 6px; }
    .equiv { flex-basis: auto; }
    .nav-controls { right: 8px; }
    .nav-controls button { width: 38px; height: 38px; font-size: 18px; }
    .demo-bar { position: static; width: auto; grid-auto-flow: column; padding: 6px; font-size: 12px; }
    .demo-bar strong { display: none; }
    .demo-bar button, .demo-bar a { padding: 6px 8px; text-align: center; }
}

/* ---------- Mode compact : téléphones (portrait et paysage) ---------- */
@media (max-width: 760px), (max-height: 560px) {
    .card { border-radius: 12px; }
    .card h2 { font-size: 12px; margin-bottom: 3px; }
    .board-sub { font-size: 10px; margin: -2px 0 4px; }
    .demo-bar button, .demo-bar a { white-space: normal; }
    .goal { padding: 6px 10px 8px; }
    .goal-value { margin-bottom: 5px; gap: 5px; }
    .goal-value .cur { font-size: 22px; }
    .goal-value .tot { font-size: 15px; }
    .goal-track { height: 9px; }
    .milestones { font-size: 11px; gap: 2px; margin-top: 5px; }
    .board { padding: 6px 8px; }
    .board ol { max-height: 45vh; overflow-y: auto; }
    .board li { gap: 5px; margin-bottom: 4px; padding: 2px 6px 2px 2px; font-size: 12px; }
    .board .swatch { width: 26px; height: 26px; }
    .board .swatch img { max-width: 20px; max-height: 20px; }
    .board .km small { font-size: .75em; }
    .phrase { padding: 7px 10px; font-size: 12px; gap: 8px; cursor: pointer; }
    .phrase img { width: 24px; }
    .phrase .txt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .phrase.expanded .txt { display: block; }
    .phrase .next { display: none; }
    .phrase.expanded .next { display: block; }
    .equiv { padding: 6px 10px; font-size: 12px; }
    .equiv .next { display: none; }
    .team-card { padding: 14px 16px; }
    .team-card h3 { font-size: 18px; }
}

/* Téléphone à l'horizontale : tout sur une ligne en haut, une ligne en bas */
@media (max-height: 560px) and (orientation: landscape) {
    .hud-top { grid-template-columns: minmax(70px, 110px) minmax(0, 1fr) minmax(0, 1.1fr) minmax(50px, 80px); align-items: start; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); }
    .board { grid-column: auto; }
    .board ol { max-height: 34vh; overflow: auto; }
    .logo-box { height: 44px; }
    .logo-bnl { display: block; } /* 4e colonne : Bike'n Learn reste sur la même ligne */
    .hud-bottom { flex-direction: row; left: max(8px, env(safe-area-inset-left)); right: max(60px, env(safe-area-inset-right)); }
    .phrase .txt { -webkit-line-clamp: 1; }
    .nav-controls { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); right: max(8px, env(safe-area-inset-right)); transform: none; gap: 4px; }
    .nav-controls button { width: 34px; height: 34px; font-size: 16px; }
    .equiv { flex: 0 1 260px; }
    .demo-bar { position: absolute; left: 0; bottom: calc(100% + 6px); }
}

/* Écrans peu hauts (portables 13-14") : bandeaux du bas plus compacts pour laisser la place à la course */
@media (max-height: 820px) and (min-width: 761px) {
    .phrase, .equiv { padding: 6px 12px; font-size: 14px; }
    .phrase .txt { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
    .phrase.expanded .txt { display: block; }
    .phrase .next, .equiv .next { display: none; }
    .phrase img { width: 28px; }
    .demo-bar { padding: 5px 8px; font-size: 13px; bottom: calc(100% + 6px); }
    .demo-bar button, .demo-bar a { padding: 5px 9px; }
    .logo-box { height: 76px; }
}

/* Écrans tactiles : on zoome avec les doigts, les boutons +/− sont inutiles */
@media (pointer: coarse) {
    .nav-controls [data-nav="in"], .nav-controls [data-nav="out"] { display: none; }
    .nav-controls { opacity: .8; }
}

/* Très grands écrans (TV 4K) */
@media (min-width: 2400px) {
    .hud-top { grid-template-columns: minmax(200px, 320px) minmax(380px, 560px) minmax(420px, 600px) minmax(180px, 280px); top: 30px; left: 40px; right: 40px; }
    .logo-box { height: 160px; }
    .board li { padding: 6px 12px 6px 6px; }
    .board .swatch { width: 52px; height: 52px; }
    .board .swatch img { max-width: 40px; max-height: 40px; }
    .board ol { max-height: 50vh; }
}
