html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, sans-serif;
  background-color: #2d2d2d;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.04) 1px, transparent 2px),
    radial-gradient(circle at 80% 80%, rgba(255,255,255,0.03) 1px, transparent 2px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.02) 1px, transparent 2px),
    repeating-linear-gradient(45deg, #2d2d2d 0 2px, #333 2px 3px),
    repeating-linear-gradient(-45deg, #2d2d2d 0 2px, #333 2px 3px);
  background-size: 30px 30px, 25px 25px, 40px 40px, 6px 6px, 6px 6px;
  background-position: 0 0, 10px 10px, 20px 20px, 0 0, 0 0;
  background-repeat: repeat;
  color: white;
  overflow-x: hidden;
}

.btn-leaderboard {
  position: fixed;
  top: 20px;
  left: 0;
  background: linear-gradient(90deg, #ffcc00, #ff6600);
  border: none;
  color: #222;
  font-weight: bold;
  font-size: 16px;
  border-radius: 0 12px 12px 0;
  cursor: pointer;
  box-shadow: 0 0 8px #ff6600;
  user-select: none;

  height: 48px;
  width: auto;
  padding: 0 12px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  transition: width 0.3s ease, padding 0.3s ease;
}

/* Always show the icon */
.btn-leaderboard .icon {
  flex-shrink: 0;
  font-size: 20px;
}

/* Hide the text by default */
.btn-leaderboard .text {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  margin-left: 8px;
  transition: opacity 0.3s ease, max-width 0.3s ease;
}

/* On hover, reveal the text */
.btn-leaderboard:hover .text {
  opacity: 1;
  max-width: 120px;
}


/* Leaderboard Modal */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  z-index: 30;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: #1a1a1a;
  color: #fff;
  border-radius: 14px;
  width: 90vw;
  max-width: 400px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 0 30px #ffcc00;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* --- Leaderboard Enhancements --- */

#leaderboardList {
  list-style: none;
  padding-left: 0;
  margin-bottom: 20px;
  text-align: left;
  font-size: 18px;
}

#leaderboardList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  background: linear-gradient(90deg, #333, #555);
  box-shadow: inset 0 0 8px #ffcc00;
  user-select: none;
  opacity: 0;
  transform: translateX(-20px);
  animation: slideFadeIn 0.4s forwards;
}

@keyframes slideFadeIn {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#leaderboardList li:nth-child(1) {
  background: linear-gradient(90deg, #ffdd00, #ffbb00);
  color: #222;
  font-weight: bold;
  box-shadow: 0 0 12px #ffdd00;
}
#leaderboardList li:nth-child(2) {
  background: linear-gradient(90deg, #c0c0c0, #a9a9a9);
  color: #111;
  font-weight: bold;
  box-shadow: 0 0 10px #aaa;
}
#leaderboardList li:nth-child(3) {
  background: linear-gradient(90deg, #cd7f32, #a0522d);
  color: #fff;
  font-weight: bold;
  box-shadow: 0 0 10px #a0522d;
}

#leaderboardList li img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 10px;
  object-fit: contain;
  flex-shrink: 0;
}

#leaderboardList li .racer-name {
  flex-grow: 1;
  font-weight: bold;
  font-size: 16px;
  text-align: left;
  white-space: nowrap;
}

#leaderboardList li .progress {
  font-weight: bold;
  color: black;
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}



/* Close button */
#closeLeaderboardBtn {
  background: #ff6600;
  border: none;
  color: white;
  padding: 10px 22px;
  border-radius: 20px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 0 10px #ff6600;
  transition: background-color 0.2s ease;
  user-select: none;
}

#closeLeaderboardBtn:hover {
  background: #ff3300;
}

/* Flex container for h1 to align items horizontally */
h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  text-align: center;
  padding: 20px;
  background: #D70564;
  margin: 0;
  color: white;
  user-select: none;
  position: relative;
  z-index: 10;
}

#editBtn {
  position: absolute;
  top: 14px;
  right: 20px;
  background-color: black;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: bold;
  user-select: none;
  transition: background-color 0.3s ease;
  z-index: 11;
}

#editBtn:active {
  background-color: #333;
}

.race-container {
  margin-top: 0;
  position: relative;
  width: 100%;
  z-index: 5;
}

.race-track {
  width: 99.2vw;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-auto-rows: 70px;
  gap: 1px;
  position: relative;
}

.lane {
  position: relative;
  height: 70px;
  width: 100%;
  border-top: 1px solid rgba(255,255,255,0.15);
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.start-line, .finish-line {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 40px;
  background: repeating-linear-gradient(to bottom, black 0 20px, white 20px 40px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1;
}

.start-line { left: 80px; }
.finish-line { right: 50px; }

.line-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: white;
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 16px;
  text-align: center;
  text-shadow: 1px 1px 3px black;
  white-space: nowrap;
  user-select: none;
}

.racer {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 80px;
  width: 100px;
  display: flex;
  align-items: center;
  user-select: none;
  z-index: 5;
}

.photo-bubble {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #2c3e50;
  background: white;
  flex-shrink: 0;
}

.photo-bubble img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  display: block;
}

.car {
  position: relative;
  width: 60px;
  height: 60px;
  margin-left: 10px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.car.motorcycle-rotate {
  width: 80px;
  height: 80px;
}

.car.motorcycle-rotate .progress-number {
  transform: translate(-50%, -60%);
  font-size: 16px;
}

.car.motorcycle-rotate img {
  transform: rotate(90deg);
}

.car img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  display: block;
}

.progress-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: bold;
  font-size: 18px;
  color: white;
  text-shadow:
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000,
    1px 1px 0 #000;
  background-color: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
  border-radius: 8px;
  pointer-events: none;
  user-select: none;
  z-index: 10;
  white-space: nowrap;
}

.racer-name {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  font-weight: bold;
  font-style: italic;
  color: white;
  text-shadow:
    1px 1px 0 #000,
    -1px -1px 0 #000,
    1px -1px 0 #000,
    -1px 1px 0 #000;
  z-index: 2;
  user-select: none;
  pointer-events: none;
  transition: transform 0.3s ease;
}

.racer-name.move-left {
  transform: translate(-600%, -50%);
}

#modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 20;
  justify-content: center;
  align-items: center;
}

#modalContent {
  background: #222;
  border-radius: 10px;
  padding: 20px;
  width: 90vw;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  color: white;
  display: flex;
  flex-direction: column;
}

#modalContent h2 {
  margin-top: 0;
  margin-bottom: 15px;
  text-align: center;
  color: #D70564;
}

.racer-edit {
  background: #333;
  margin-bottom: 15px;
  padding: 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.racer-edit label {
  font-weight: bold;
  color: white;
  user-select: none;
}

.racer-edit input {
  padding: 6px 8px;
  border-radius: 4px;
  border: none;
  font-size: 14px;
  color: black;
  width: 100%;
  box-sizing: border-box;
}

.delete-btn, #addRacerBtn, #closeModalBtn {
  margin-top: 6px;
  background: #D70564;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: bold;
  align-self: center;
  user-select: none;
}

#closeModalBtn {
  background: black;
}

.delete-btn:hover, #addRacerBtn:hover {
  background: #a0034d;
}

#closeModalBtn:hover {
  background: #333;
}
