* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: #f3f4f6 url('../assets/fondo-tiempos.jpg') center/cover fixed;
  color: #111827;
}
.wrap {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
}
.top {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.brand {
  display: grid;
  gap: 6px;
}
.badge {
  font-size: 34px;
  line-height: 1.05;
  font-weight: 950;
  padding: 12px 14px;
  border: 1px solid #d8dbe6;
  border-radius: 16px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.statusLine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.sub, .pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 12px;
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(216,219,230,.9);
}
.pill.online { color: #065f46; background: #d1fae5; border-color: #a7f3d0; }
.pill.warn { color: #92400e; background: #fef3c7; border-color: #fde68a; }
.pill.offline { color: #991b1b; background: #fee2e2; border-color: #fecaca; }
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  background: rgba(255,255,255,.96);
  border: 1px solid #d8dbe6;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.13);
}
.field { display: grid; gap: 4px; }
label { font-weight: 950; font-size: 12px; opacity: .82; }
select, button {
  min-height: 44px;
  font-size: 16px;
  padding: 9px 10px;
  border: 1px solid #d8dbe6;
  border-radius: 12px;
  background: #fff;
  font-weight: 900;
}
button {
  cursor: pointer;
  color: #fff;
  background: #c0392b;
  border-color: #a93226;
  min-width: 70px;
}
button:disabled { opacity: .55; cursor: wait; }
.block {
  border: 1px solid #d8dbe6;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255,255,255,.98);
  box-shadow: 0 3px 16px rgba(0,0,0,.18);
  min-height: 0;
}
.titlebar {
  padding: 12px;
  font-size: 24px;
  font-weight: 950;
  background: linear-gradient(90deg, #fff, #f4f5ff);
  border-bottom: 1px solid #e3e6f2;
}
.table-container { overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; min-width: 820px; }
th, td {
  border: 1px solid #e6e8f1;
  padding: 8px;
  text-align: center;
  font-size: 14px;
}
th {
  background: #c0392b;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
  font-weight: 950;
}
tbody tr:nth-child(even) td { background: rgba(0,0,0,.05); }
tbody tr:hover td { background: rgba(230,240,255,.85); }
.pos { font-weight: 950; font-size: 1.12em; }
.total { font-weight: 950; color: #b91c1c; font-size: 1.16em; }
.positionWrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 26px;
  font-variant-numeric: tabular-nums;
}
.positionDelta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 31px;
  height: 23px;
  padding: 0 6px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 950;
  line-height: 1;
}
.positionDelta.gained { color: #137333; background: #e5f5e9; }
.positionDelta.lost { color: #b3261e; background: #fde8e7; }
.stageTimeWrap {
  display: inline-grid;
  justify-items: center;
  gap: 2px;
  min-width: 76px;
  font-variant-numeric: tabular-nums;
}
.stageTimeValue { color: #111827; font-weight: 950; }
.stageTimeChange {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 16px;
}
.timeDelta {
  font-size: 11px;
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}
.timeDelta.faster { color: #137333; }
.timeDelta.slower { color: #b3261e; }
.timeDelta.same { color: #6b7280; }
.personalBest {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 16px;
  padding: 0 4px;
  border-radius: 3px;
  background: #111827;
  color: #fff!important;
  font-size: 9px;
  font-weight: 950;
  line-height: 1;
}
.cards { display: none; }
.empty { padding: 18px; font-weight: 950; opacity: .75; }
.cat-gt td, .card.cat-gt { background: rgba(52, 152, 219, 0.16); }
.cat-rally2 td, .card.cat-rally2 { background: rgba(46, 204, 113, 0.16); }
.cat-lineal td, .card.cat-lineal { background: rgba(241, 196, 15, 0.18); }
.cat-infantil td, .card.cat-infantil { background: rgba(155, 89, 182, 0.16); }
.cat-mk2scalextric td, .card.cat-mk2scalextric { background: rgba(244, 114, 182, 0.14); }
.cat-teamslot td, .card.cat-teamslot { background: rgba(20, 184, 166, 0.14); }

@media (min-width: 900px) {
  .wrap { padding: 14px; }
  .top { grid-template-columns: 1fr auto; align-items: end; }
  .single .table-container { height: calc(100vh - 152px); }
}

@media (max-width: 720px) {
  body { background-attachment: scroll; }
  .wrap { padding-left: 7px; padding-right: 7px; }
  .badge { padding: 11px; font-size: 24px; }
  .filters {
    position: sticky;
    top: 0;
    z-index: 5;
    grid-template-columns: 1fr 1fr;
    border-radius: 14px;
  }
  .filters button { grid-column: 1 / -1; min-height: 42px; }
  select { width: 100%; min-height: 46px; font-size: 15px; }
  .titlebar { padding: 10px; font-size: 20px; }
  .table-container { overflow: visible; }
  table { display: none; }
  .cards {
    display: grid;
    gap: 8px;
    padding: 8px;
  }
  .card {
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 11px;
    background: #fff;
    box-shadow: 0 1px 6px rgba(0,0,0,.08);
  }
  .cardTop, .cardBottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .position, .dorsal {
    font-size: 23px;
    font-weight: 950;
    color: #b91c1c;
  }
  .category, .tag {
    border-radius: 999px;
    padding: 5px 8px;
    background: rgba(255,255,255,.8);
    border: 1px solid rgba(0,0,0,.08);
    font-weight: 950;
    font-size: 12px;
    white-space: nowrap;
  }
  .time {
    margin-top: 5px;
    font-size: 42px;
    line-height: 1;
    font-weight: 950;
    color: #b91c1c;
    letter-spacing: 0;
  }
  .name {
    margin-top: 7px;
    font-size: 18px;
    line-height: 1.15;
    font-weight: 950;
  }
  .meta {
    margin-top: 4px;
    font-size: 14px;
    font-weight: 800;
    color: #374151;
  }
  .meta.strong { color: #111827; }
  .cardBottom {
    margin-top: 9px;
    font-size: 13px;
    font-weight: 950;
    color: #374151;
  }
}

/* V5: clasificación de pasadas por acumulado + desglose de pasadas/tramos */
.smalltime {
  font-weight: 900;
  white-space: nowrap;
}
.tramoTime {
  color: #374151;
}
.total.current {
  color: #1f2937;
}
.total.accumulated {
  color: #b91c1c;
  font-size: 1.22em;
}
.time span {
  display: block;
  font-size: 12px;
  line-height: 1.1;
  letter-spacing: 0;
  color: #374151;
  margin-bottom: 2px;
}
.summaryGrid, .tramosGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 9px;
}
.summaryGrid div, .tramosGrid div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 12px;
  padding: 7px 8px;
  background: rgba(255,255,255,.72);
  font-size: 13px;
  font-weight: 900;
}
.summaryGrid div span, .tramosGrid div span {
  color: #111827;
  font-variant-numeric: tabular-nums;
}
.tramosGrid .stageTimeWrap {
  min-width: 0;
  justify-items: end;
}
.tramosGrid .stageTimeChange { justify-content: flex-end; }
.tramosGrid .timeDelta.faster { color: #137333; }
.tramosGrid .timeDelta.slower { color: #b3261e; }
.summaryGrid .currentBox {
  background: #fee2e2;
  border-color: #fecaca;
}
.tramosTitle {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 950;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0;
}
@media (max-width: 720px) {
  .card .time {
    display: grid;
    gap: 2px;
  }
}
@media (max-width: 390px) {
  .time { font-size: 36px; }
}
