/* ═══════════════════════════════════════════════════════════
   Speed Run — écran de fin
   ═══════════════════════════════════════════════════════════ */

#speedrun-end-screen {
  position: fixed;
  inset: 0;
  background: #0f1117;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sr-end-inner {
  background: #1a1d2e;
  border: 1px solid rgba(99, 120, 255, 0.3);
  border-radius: 18px;
  padding: 36px 40px;
  max-width: 520px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin: auto;
}

.sr-end-title {
  font-size: 24px;
  font-weight: 800;
  color: #e8eefc;
  text-align: center;
}

.sr-end-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.sr-end-stat {
  flex: 1;
  background: rgba(99, 120, 255, 0.07);
  border: 1px solid rgba(99, 120, 255, 0.3);
  border-radius: 14px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.sr-end-stat::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #6378ff, #a78bfa);
}

.sr-end-stat-label {
  font-size: 11px;
  font-weight: 700;
  color: #a78bfa;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sr-end-stat-value {
  font-size: 32px;
  font-weight: 800;
  color: #e8eefc;
  line-height: 1;
}

.sr-end-stat-total,
.sr-end-stat-unit {
  font-size: 16px;
  font-weight: 500;
  color: #718096;
  margin-left: 2px;
}

.sr-end-rank-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sr-end-rank-title {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sr-rank-badge {
  font-size: 22px;
  font-weight: 800;
  color: #e8eefc;
  margin-bottom: 8px;
}

.sr-rank-sub {
  text-align: center;
  margin-top: 6px;
  font-size: 12px;
  color: #ffffff;
}

.sr-rank-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sr-rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
}

.sr-rank-row--me {
  background: rgba(99, 120, 255, 0.12);
  border-color: rgba(99, 120, 255, 0.4);
}

.sr-rank-pos {
  min-width: 28px;
  text-align: center;
  font-size: 15px;
}

.sr-rank-name {
  flex: 1;
  font-weight: 500;
  color: #e2e8f0;
}

.sr-rank-correct {
  font-size: 12px;
  color: #4ade80;
  font-weight: 600;
}

.sr-rank-time {
  font-size: 12px;
  background: rgba(124, 106, 255, 0.2);
  color: #a78bfa;
  border-radius: 20px;
  padding: 2px 9px;
  font-weight: 600;
}

.sr-end-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.sr-end-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition:
    opacity 0.15s,
    transform 0.15s;
  cursor: pointer;
}

.sr-end-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.sr-end-btn-primary {
  background: #7c6aff;
  color: #fff;
}

.sr-end-btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

@media (max-width: 520px) {
  .sr-end-inner {
    padding: 24px 16px;
    gap: 16px;
  }
  .sr-end-stats {
    flex-direction: column;
  }
}

@media (max-width: 400px) {
  #speedrun-end-screen {
    padding: 10px;
    align-items: flex-start;
  }
  .sr-end-inner {
    padding: 20px 12px;
    gap: 12px;
    border-radius: 14px;
  }
  .sr-end-score-big {
    font-size: 40px;
  }
  .sr-end-avg,
  .sr-end-beat {
    font-size: 12px;
  }
  .sr-end-histogram {
    height: 60px;
    margin: 10px 0 2px;
  }
  .sr-end-tabs {
    margin: 10px 0 2px;
  }
  .sr-end-tab {
    padding: 7px 8px;
    font-size: 12px;
  }
  .sr-end-history-grid {
    max-height: 220px;
  }
  .sr-end-actions {
    flex-direction: column;
    gap: 8px;
  }
  .sr-end-btn {
    padding: 10px 20px;
  }
}

/* ── Rang fin de partie — classes survie réutilisées ── */
.survie-lb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.survie-lb-rank {
  font-size: 13px;
  font-weight: 700;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: #9aa3b2;
  background: rgba(255, 255, 255, 0.08);
}

.survie-lb-rank.gold {
  background: linear-gradient(135deg, #ffd700, #f59e0b);
  color: #000;
}

.survie-lb-rank.silver {
  background: linear-gradient(135deg, #f1f5f9, #cbd5e1);
  color: #000;
}

.survie-lb-rank.bronze {
  background: linear-gradient(135deg, #d97706, #92400e);
  color: #fff;
}

.survie-lb-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: #e8eefc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.speedrun-lb-score {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.speedrun-correct {
  font-size: 12px;
  color: #4ade80;
  font-weight: 600;
}

.speedrun-avg-time {
  font-size: 12px;
  background: rgba(124, 106, 255, 0.2);
  color: #fff;
  border-radius: 20px;
  padding: 2px 9px;
  font-weight: 600;
}

#speedrun-restart-btn {
  display: none;
  align-items: center;
  align-self: flex-start;
  gap: 5px !important;
  padding: 8px 16px !important;
  width: auto !important;
  height: auto !important;
  min-width: unset !important;
  border-radius: 20px !important;
  border: 1px solid rgba(124, 106, 255, 0.4) !important;
  background: rgba(124, 106, 255, 0.1) !important;
  color: #ffffff !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  letter-spacing: 0.06em !important;
  text-transform: uppercase !important;
  text-shadow: none !important;
  box-shadow: none !important;
  line-height: normal !important;
  transition:
    background 0.15s,
    border-color 0.15s !important;
}
#speedrun-restart-btn:hover {
  background: rgba(124, 106, 255, 0.22) !important;
  border-color: rgba(124, 106, 255, 0.7) !important;
}
#speedrun-restart-btn i {
  font-size: 10px !important;
}

@media (max-width: 768px) {
  #speedrun-restart-btn {
    font-size: 9px !important;
    padding: 3px 8px !important;
    gap: 3px !important;
    letter-spacing: 0.02em !important;
  }
  #speedrun-restart-btn i {
    font-size: 8px !important;
  }
  #restartSpeedRunDialog .dialog-box {
    width: 90%;
    max-width: 320px;
    padding: 20px 16px;
  }
  #restartSpeedRunDialog .dialog-box p:first-child {
    font-size: 15px;
  }
  #restartSpeedRunDialog .dialog-buttons {
    gap: 8px;
  }
  #restartSpeedRunDialog .dialog-btn {
    padding: 10px 16px;
    font-size: 13px;
  }
}

/* ═══════════════════════════════════════════════════════════
   Speed Run — écran de fin v2
   ═══════════════════════════════════════════════════════════ */

.sr-end-header {
  position: relative;
  text-align: center;
}

.sr-end-kicker {
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

@media (max-width: 520px) {
  .sr-end-kicker {
    font-size: 18px;
  }
}

.sr-end-score {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  margin: 4px 0 0;
}

.sr-end-score-big {
  font-size: 56px;
  font-weight: 800;
  color: #a78bfa;
  line-height: 1;
}

.sr-end-score-total {
  font-size: 26px;
  font-weight: 600;
  color: #718096;
  line-height: 1;
  transform: translateY(-2px); /* ajuste -1 à -4px selon le rendu chez toi */
}

.sr-end-avg {
  text-align: center;
  font-size: 13px;
  color: #9aa3b2;
  margin: 6px 0 0;
}

.sr-end-avg strong {
  color: #e8eefc;
}

.sr-end-beat {
  text-align: center;
  font-size: 13px;
  color: #e8eefc;
  margin: 8px 0 0;
  min-height: 18px;
}

.sr-end-histogram {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  height: 80px;
  padding: 0 4px;
}

.sr-hist-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  max-width: 26px;
}

.sr-hist-bar {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
}

.sr-hist-bar.mine {
  background: #7c6aff;
}

.sr-hist-bar-label {
  font-size: 10px;
  color: #718096;
}

.sr-hist-bar-label.mine {
  color: #a78bfa;
  font-weight: 700;
}

.sr-end-tabs {
  display: flex;
  gap: 8px;
}

.sr-end-tab {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #9aa3b2;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1.3;
  box-sizing: border-box;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  text-shadow: none;
  box-shadow: none;
  white-space: nowrap;
  width: auto;
  height: auto;
  transition:
    background 0.15s,
    color 0.15s;
}

.sr-end-tab.active {
  background: rgba(124, 106, 255, 0.28);
  color: #ffffff;
  border: 1px solid rgba(124, 106, 255, 0.5);
}

.sr-end-tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.04);
}

.sr-end-tab-content.hidden {
  display: none;
}

.sr-end-history-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  box-sizing: border-box;
}

.sr-hist-card {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 6px;
  text-align: center;
  box-sizing: border-box;
  min-width: 0;
  height: 100%;
}

.sr-hist-cover,
.sr-hist-cover-empty {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 6px;
  display: block;
  flex-shrink: 0;
}

.sr-hist-cover-empty {
  background: rgba(255, 255, 255, 0.05);
}

.sr-hist-title {
  font-size: 10px;
  font-weight: 600;
  color: #e2e8f0;
  line-height: 1.3;
  height: 2.6em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.sr-hist-time {
  font-size: 11px;
  font-weight: 700;
  margin-top: auto;
  padding-top: 2px;
}

.sr-hist-time.fast {
  color: #4ade80;
}
.sr-hist-time.mid {
  color: #ffd166;
}
.sr-hist-time.slow {
  color: #a78bfa;
}
.sr-hist-time.miss {
  color: #f87171;
}

.sr-end-rank-section {
  margin-top: 4px;
}

.sr-rank-sub {
  text-align: center;
  margin-top: 6px;
  font-size: 12px;
  color: #ffffff;
}

@media (max-width: 520px) {
  .sr-end-history-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .sr-end-score-big {
    font-size: 44px;
  }
}

.sr-end-tab:focus {
  outline: none;
}

.sr-end-tab:focus-visible {
  outline: 2px solid rgba(124, 106, 255, 0.6);
  outline-offset: 2px;
}

.sr-end-share-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 8px;
}

.sr-end-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #9aa3b2;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  text-shadow: none;
  box-shadow: none;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.sr-end-icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #e8eefc;
  border-color: rgba(255, 255, 255, 0.24);
}

.sr-end-icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

@media (max-width: 400px) {
  .sr-end-icon-btn {
    width: 28px;
    height: 28px;
  }
  .sr-end-icon-btn svg {
    width: 14px;
    height: 14px;
  }
  .sr-end-share-actions {
    gap: 6px;
  }
}

@media (min-width: 1101px) and (max-width: 1800px) {
  #speedrun-restart-btn {
    margin-left: auto !important;
  }
}
