html, body { height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--brand); color: #fff; z-index: 1000; }
.bar .ico { width: 30px; height: 30px; border-radius: 8px; }
.bar .title { flex: 1; min-width: 0; }
/* Botón de la carrera actual (abre el selector) */
.evbtn { display: flex; align-items: baseline; gap: 8px; background: none; border: 0; color: #fff; padding: 0; cursor: pointer; max-width: 100%; text-align: left; }
.evbtn #evName { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.evbtn .chg { flex: none; font-size: 11px; font-weight: 700; background: rgba(255,255,255,.22); border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.bar .clock { font-size: 12px; opacity: .9; font-variant-numeric: tabular-nums; }
.bar .btn { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); color: #fff; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #ffc9c9; }
.conn.on { background: #b2f2bb; box-shadow: 0 0 0 3px rgba(178,242,187,.35); }

main { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-btns { position: absolute; right: 10px; top: 60px; z-index: 600; display: flex; flex-direction: column; gap: 8px; }
.fab { width: 40px; height: 40px; border-radius: 10px; border: 0; background: #fff; box-shadow: var(--shadow); font-size: 18px; cursor: pointer; }
.fab#followBtn { filter: grayscale(1); opacity: .75; }
.fab#followBtn.on { filter: none; opacity: 1; background: #fff3bf; box-shadow: 0 0 0 2px #fab005, var(--shadow); }
.follow-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 1300; background: rgba(22,32,43,.9); color: #fff; padding: 7px 12px; border-radius: 99px; font-size: 13px; cursor: pointer; white-space: nowrap; }

/* Panel: barra inferior deslizante en móvil, lateral en escritorio */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; height: 42%; background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.15); z-index: 700; display: flex; flex-direction: column; transition: height .2s; padding-bottom: env(safe-area-inset-bottom); }
.sheet.min { height: 96px; }
.sheet.max { height: 85%; }
.grab { padding: 8px 0 2px; display: flex; justify-content: center; cursor: grab; touch-action: none; }
.grab span { width: 42px; height: 5px; border-radius: 3px; background: #ced4da; }
.seg { display: flex; margin: 4px 12px 8px; background: #f1f3f5; border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.on { display: flex; }
.filters { display: flex; gap: 6px; padding: 0 12px 8px; }
.filters input, .filters select { flex: 1; }
#favOnly.on { background: #fff3bf; border-color: #fab005; }
.plist { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }

.pi { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-top: 1px solid #f1f3f5; cursor: pointer; }
.pi:hover { background: #fff8f2; }
.pi.sel { background: #fff3bf; }
.pi .pos { width: 26px; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.pi .bib { min-width: 38px; height: 26px; border-radius: 13px; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 12px; padding: 0 6px; }
.pi .info { flex: 1; min-width: 0; }
.pi .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pi .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pi .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.star { border: 0; background: none; font-size: 22px; color: #ced4da; cursor: pointer; padding: 0 4px; line-height: 1; }
.star.on { color: #fab005; }
.empty { padding: 16px; color: var(--muted); text-align: center; }

.pcard { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 1200; background: #fff; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.2); padding: 12px 14px; }
.pcard h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.pcard .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.pcard .grid div { background: #f8f9fa; border-radius: 8px; padding: 6px 8px; }
.pcard .grid b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.pcard .grid span { font-size: 11px; color: var(--muted); }
.pcard .close { position: absolute; right: 8px; top: 6px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.pcard .splits { margin-top: 8px; font-size: 13px; max-height: 120px; overflow: auto; }
.pcard .splits div { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px dashed #f1f3f5; }
.pcard .acts { display: flex; gap: 8px; margin-top: 10px; }

/* Perfil del recorrido */
#profBtn { display: flex; align-items: center; justify-content: center; color: var(--ink); }
#profBtn.on { background: #fff3e6; box-shadow: 0 0 0 2px #e8590c, var(--shadow); color: #e8590c; }
#profBtn.hidden { display: none; }
.elev-card { position: absolute; left: 10px; right: 60px; top: 10px; height: 140px; z-index: 650; }
body.fs .elev-card { top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) {
  .elev-card { top: auto; bottom: 12px; left: 56px; right: 392px; height: 160px; }
  body.fs .elev-card { right: 60px; }
}

@media (min-width: 900px) {
  .sheet, .sheet.min, .sheet.max { left: auto; top: 0; right: 0; width: 380px; height: auto; border-radius: 0; box-shadow: -2px 0 12px rgba(0,0,0,.08); }
  .grab { display: none; }
  .map-btns { right: 392px; }
  .pcard { left: 60px; right: auto; width: 380px; }
  #map .leaflet-top.leaflet-right { right: 380px; }
}

/* En el móvil el zoom se hace con dos dedos: los botones +/- quedarían tapados por el panel inferior */
@media (max-width: 899px) { .leaflet-control-zoom { display: none; } }

/* Participantes seguidos */
.favbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 12px 8px; }
.favbar .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #fff3bf; border: 1px solid #fab005; border-radius: 99px; padding: 2px 4px 2px 10px; font-size: 13px; cursor: pointer; max-width: 100%; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.chip button { border: 0; background: rgba(0,0,0,.08); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.chip button:hover { background: var(--sos); color: #fff; }
.favbar .clear { border: 0; background: none; color: var(--sos); font-size: 12px; font-weight: 600; cursor: pointer; padding: 4px; }

/* Pantalla completa del mapa */
#fsBtn { display: flex; align-items: center; justify-content: center; color: var(--ink); }
#fsBtn .i-exit { display: none; }
body.fs #fsBtn .i-enter { display: none; }
body.fs #fsBtn .i-exit { display: block; }
body.fs #fsBtn { background: var(--brand); color: #fff; }
body.fs .bar, body.fs .sheet, body.fs #card { display: none !important; }
body.fs .map-btns { right: 10px; top: max(10px, env(safe-area-inset-top)); }
body.fs #map .leaflet-top.leaflet-right { right: 0; }
body.fs .leaflet-control-layers { margin-top: 0; }
body.fs .map-btns { top: max(60px, calc(env(safe-area-inset-top) + 50px)); }
.fsinfo .evlogo { height: 24px; margin: -3px 8px -3px -6px; vertical-align: middle; }
.fsinfo { display: none; position: absolute; left: 10px; top: max(10px, env(safe-area-inset-top)); z-index: 900; max-width: calc(100% - 80px);
  background: rgba(22,32,43,.85); color: #fff; padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
body.fs .fsinfo { display: block; }
body.fs .follow-hint { top: auto !important; bottom: calc(14px + env(safe-area-inset-bottom)) !important; left: 50% !important; }
@media (min-width: 900px) { body.fs .map-btns { right: 10px; } }

/* Selector de carreras */
.chooser .modal { width: min(480px, 94vw); padding: 16px 0 10px; }
.chooser h3 { padding: 0 16px; }
.chooser .grp { padding: 6px 16px 2px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.chooser .ev { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 11px 16px; cursor: pointer; border-top: 1px solid #f1f3f5; }
.chooser .ev:hover { background: #fff8f2; }
.chooser .ev.cur { background: #fff3bf; }
.chooser .ev .n { flex: 1; min-width: 0; }
.chooser .ev b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chooser .ev small { color: var(--muted); }
.chooser .tag { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; color: #fff; }
.tag.live { background: #e03131; } .tag.next { background: #1c7ed6; } .tag.past { background: #868e96; }
.chooser .foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 0; gap: 8px; flex-wrap: wrap; }
.chooser .reset { border: 0; background: none; color: var(--sos); font-size: 12px; font-weight: 600; cursor: pointer; padding: 4px 0; }

.filters select.hidden { display: none; }
.filters select { min-width: 0; }
/* Móvil: con logo del organizador se oculta el icono de la app para dejar sitio al nombre de la prueba */
@media (max-width: 600px) {
  .bar:has(#evLogo:not(.hidden)) .ico { display: none; }
  .bar .evlogo { height: 30px; max-width: 84px; }
}
