/* ==========================================================================
   Chronospheres — suivi GPS d'epreuves
   --------------------------------------------------------------------------
   Thème clair par défaut : un départ se donne de jour et la carte publique se
   consulte au soleil. Le thème sombre sert les étapes de nuit et se déclenche
   sur la préférence système, ou à la main par data-theme.

   La couleur ne porte que deux informations : l'identité du rôle et l'état
   d'alerte. Jaune haute visibilité pour la tête de course, rouge signal pour
   le serre-file — les deux matériaux réels des gilets et fanions.
   ========================================================================== */

:root {
  --paper:      #eef1f2;
  --surface:    #ffffff;
  --surface-2:  #f7f9f9;
  --ink:        #141f28;
  --ink-soft:   #44555f;
  --muted:      #6b7d88;
  --line:       #d2dade;
  --line-soft:  #e4eaed;

  --head:       #a8c200;   /* moto de tête, haute visibilité */
  --head-ink:   #5c6c00;
  --sweep:      #cf3418;   /* serre-file, rouge signal */
  --sweep-ink:  #a52810;
  --alert:      #c87200;
  --ok:         #0f7a52;

  --radius:   3px;
  --radius-lg: 6px;
  --panel-w:  380px;

  --sans: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --cond: "Barlow Condensed", "Barlow", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:     #0d141a;
    --surface:   #151f27;
    --surface-2: #1b2832;
    --ink:       #e7eef2;
    --ink-soft:  #b3c2cc;
    --muted:     #7d8f9c;
    --line:      #27343e;
    --line-soft: #1f2b34;

    --head:      #c3e017;
    --head-ink:  #c3e017;
    --sweep:     #f2573a;
    --sweep-ink: #f2573a;
    --alert:     #f0a030;
    --ok:        #2fb584;
  }
}

:root[data-theme="dark"] {
  --paper:     #0d141a;
  --surface:   #151f27;
  --surface-2: #1b2832;
  --ink:       #e7eef2;
  --ink-soft:  #b3c2cc;
  --muted:     #7d8f9c;
  --line:      #27343e;
  --line-soft: #1f2b34;

  --head:      #c3e017;
  --head-ink:  #c3e017;
  --sweep:     #f2573a;
  --sweep-ink: #f2573a;
  --alert:     #f0a030;
  --ok:        #2fb584;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15.5px;          /* lu à bout de bras dans un véhicule */
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

/* Les chiffres qui se rafraîchissent en direct ne doivent pas trembler. */
.num, .strip-dist, .gap-value, td.num, input[type="number"] {
  font-variant-numeric: tabular-nums;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--sweep);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- bandeau */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 52px;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--cond);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
}
.brand span { color: var(--muted); font-weight: 400; }

.topbar-event {
  font-family: var(--cond);
  font-size: 20px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.clock {
  font-family: var(--cond);
  font-size: 21px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* État de la liaison : un point et un mot, pas une icône à déchiffrer. */
.link-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  color: var(--muted);
}
.link-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.link-state[data-state="live"]    .link-dot { background: var(--ok); }
.link-state[data-state="live"]             { color: var(--ink-soft); }
.link-state[data-state="retry"]   .link-dot { background: var(--alert); }
.link-state[data-state="down"]    .link-dot { background: var(--sweep); }

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-soft);
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ------------------------------------------------------------------ cadre */

.shell {
  position: fixed;
  inset: 52px 0 0 0;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--surface-2);
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------- bande de course (hero)

   L'élément central : un ultra-trail est unidimensionnel. La réglette donne la
   position de chacun sur le parcours et l'écart tête-queue, ce qu'une carte ne
   montre pas sur un tracé en boucle.
   -------------------------------------------------------------------------- */

.strip-block {
  padding: 18px 16px 20px;
  border-bottom: 1px solid var(--line);
}

.strip-head { margin-bottom: 18px; }

.strip-route {
  display: block;
  font-family: var(--cond);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.18;
}
/* Rattache le nom du parcours à la couleur de son tracé sur la carte. Sans
   ce repère, la ligne du parcours et la traînée d'un suiveur se lisent comme
   deux versions du même trajet. */
.swatch {
  display: inline-block;
  width: 16px;
  height: 4px;
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
}

.strip-length {
  display: flex;
  gap: 15px;
  margin-top: 3px;
  font-size: 13.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.strip {
  position: relative;
  display: grid;
  grid-template-columns: 150px 14px 1fr;
  min-height: 310px;
}

.strip-rail {
  grid-column: 2;
  position: relative;
  width: 4px;
  margin: 10px 0 10px 5px;
  background: var(--line);
  border-radius: 2px;
}

/* Portion encadrée par la tête et la queue : c'est là qu'est la course. */
.strip-field {
  position: absolute;
  left: -1px;
  width: 6px;
  background: var(--ink-soft);
  border-radius: 3px;
  opacity: .32;
  transition: top .6s ease, height .6s ease;
}

.strip-ends {
  grid-column: 3;
  position: relative;
  margin: 10px 0;
}
.strip-end {
  position: absolute;
  left: 10px;
  font-family: var(--cond);
  font-size: 15px;
  color: var(--muted);
  transform: translateY(-50%);
  white-space: nowrap;
}
.strip-end[data-at="start"]  { top: 0; }
.strip-end[data-at="finish"] { top: 100%; }

/* crans : ravitaillements, bases vie, barrières horaires */
.strip-tick {
  position: absolute;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translateY(-50%);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  max-width: calc(100% - 14px);
}
.strip-tick::before {
  content: "";
  width: 7px; height: 1px;
  background: var(--line);
  margin-left: -17px;
  flex-shrink: 0;
}
.strip-tick-name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.strip-tick[data-kind="base_vie"] { color: var(--ink-soft); font-weight: 500; }
.strip-tick[data-kind="barriere"] { color: var(--alert); }

/* marqueurs des officiels, côté gauche */
.strip-marks { grid-column: 1; position: relative; margin: 10px 0; }

.strip-mark {
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  transform: translateY(-50%);
  transition: top .6s ease;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 2px 0;
  font: inherit;
  color: var(--ink);
  text-align: right;
  width: 100%;
}
.strip-mark-label {
  font-family: var(--cond);
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.strip-dist {
  font-family: var(--cond);
  font-size: 17.5px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  flex-shrink: 0;
}
.strip-mark-pip {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2.5px solid var(--surface);
  box-shadow: 0 0 0 1.5px currentColor;
  background: currentColor;
  flex-shrink: 0;
  margin-right: -3px;
}
.strip-mark[data-role="moto_tete"]   { color: var(--head-ink); }
.strip-mark[data-role="serre_file"]  { color: var(--sweep-ink); }

/* Silence = information. Un traceur muet se voit. */
.strip-mark[data-stale="1"] { opacity: .42; }
.strip-mark[data-stale="1"] .strip-mark-pip { background: transparent; }

.gap {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.gap-value {
  font-family: var(--cond);
  font-size: 31px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.gap-label { font-size: 13.5px; color: var(--muted); }

/* --------------------------------------------------------- fiches suiveurs */

.followers { padding: 6px 0 24px; }

.follower {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-left: 3px solid var(--line);
  padding: 12px 16px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
}
.follower:hover { background: var(--surface-2); }
.follower[data-role="moto_tete"]  { border-left-color: var(--head); }
.follower[data-role="serre_file"] { border-left-color: var(--sweep); }
.follower[data-selected="1"] { background: var(--surface-2); }

.follower-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.follower-name {
  font-family: var(--cond);
  font-size: 18px;
  font-weight: 600;
}
.follower-age { font-size: 13px; color: var(--muted); white-space: nowrap; }
.follower[data-stale="1"] .follower-age { color: var(--alert); font-weight: 500; }
.follower[data-stale="2"] .follower-age { color: var(--sweep); font-weight: 600; }

/* L'heure du dernier point, à côté de son ancienneté : « 14h32 » se
   communique par radio, « il y a neuf minutes » non. */
.follower-clock {
  margin-left: 7px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.follower-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 5px;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.follower-facts b { font-weight: 600; font-variant-numeric: tabular-nums; }
.follower-facts .low { color: var(--sweep); }

.follower-holder { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* ------------------------------------------------------------- états vides */

.empty {
  padding: 28px 16px;
  color: var(--muted);
  font-size: 14.5px;
}
.empty strong {
  display: block;
  font-family: var(--cond);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 5px;
}

/* ---------------------------------------------------- marqueurs sur carte */

.pin {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .45);
  display: grid;
  place-items: center;
  font-family: var(--cond);
  font-size: 15px;
  font-weight: 600;
}
/* « M10 » tient dans la pastille, mais plus à la même taille. */
.pin[data-len="3"] { font-size: 12.5px; letter-spacing: -.02em; }

.pin[data-stale="1"] { opacity: .5; }
.pin[data-stale="2"] { opacity: .5; border-style: dashed; }

.pin-tip {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
}
.pin-tip b { font-family: var(--cond); font-size: 16px; }

.leaflet-container { font-family: var(--sans); background: var(--surface-2); }
.leaflet-bar a, .leaflet-control-layers { border-radius: var(--radius) !important; }

/* L'IGN ne publie pas de fond sombre, et une carte blanche en pleine nuit
   dans un véhicule détruit la vision nocturne du passager. On assombrit les
   tuiles sans toucher au tracé ni aux marqueurs, qui doivent rester francs. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane {
    filter: brightness(.6) contrast(1.1) saturate(.82);
  }
}
:root[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(.6) contrast(1.1) saturate(.82);
}

/* ----------------------------------------------------------- sélecteur -- */

.picker {
  max-width: 620px;
  margin: 10vh auto;
  padding: 0 20px;
}
.picker h1 {
  font-family: var(--cond);
  font-size: 34px;
  font-weight: 600;
  margin: 0 0 6px;
}
.picker p { color: var(--muted); margin: 0 0 26px; }
.picker-list { display: flex; flex-direction: column; gap: 1px; }
.picker-item {
  display: block;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
}
.picker-item:hover { border-color: var(--ink-soft); }
.picker-name { font-family: var(--cond); font-size: 20px; font-weight: 600; }
.picker-meta { font-size: 13.5px; color: var(--muted); margin-top: 2px; }

body.plain { overflow: auto; }
body.plain .shell { position: static; inset: auto; display: block; }

/* ------------------------------------------------------------- téléphone */

/* Sur téléphone la page défile normalement : la carte reste collée en haut
   pendant qu'on parcourt la liste, au lieu d'enfermer le panneau dans une
   zone de défilement qui tronque les fiches sans le dire. */
@media (max-width: 860px) {
  body { overflow: auto; }
  .shell {
    position: static;
    inset: auto;
    display: flex;
    flex-direction: column;
    padding-top: 52px;
    min-height: 100%;
  }
  #map {
    order: 1;
    height: 52vh;
    position: sticky;
    top: 52px;
    z-index: 0;
  }
  .panel {
    order: 2;
    overflow: visible;
    border-right: 0;
    border-top: 1px solid var(--line);
    position: relative;
    z-index: 1;
    min-height: 48vh;
  }
  .topbar { gap: 12px; padding: 0 12px; }
  .brand span { display: none; }
  .strip { min-height: 280px; }
}

@media (max-width: 640px) {
  #link-text { display: none; }
  .brand { font-size: 21px; }
}
