#grand-derby {
  width: 100%;
  max-width: 800px;
  margin: 0.25em auto;    /* cut top/bottom margin in half */
  padding: 0;            /* remove all internal padding */
  font-family: sans-serif;
}



/* Striping only the top area */
.grand-derby-top {
  background: repeating-linear-gradient(
    45deg,
    #f8eaff,
    #f8eaff 10px,
    #e6ccf2 10px,
    #e6ccf2 20px
  );
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  padding: 0.5em 1em;
}

/* Header text */
.grand-derby-header {
  text-align: center;
  font-size: 2em; /* bigger on desktop */
  font-weight: bold;
  margin-bottom: 0.5em;
}

/* Controls */
#grand-derby .controls {
  display: flex;
  justify-content: center;
  gap: 0.5em;
}
#grand-derby select {
  padding: 0.5em 1em;
  font-size: 1em;
  border-radius: 4px;
  border: 1px solid #999;
}
#grand-derby button {
  padding: 0.6em 1.2em;
  font-size: 1em;
  border: 1px solid #7d3c98; /* 1px border */
  border-radius: 20px;
  background: linear-gradient(to bottom, #a569bd, #8e44ad);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Track */
.grand-derby-track {
  position: relative;
  height: 60vh;
  max-height: 500px;
  background: #d2b48c;
  overflow: hidden;
  /* no custom-property alias here */
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.grand-derby-lane {
  position: relative;
  height: calc(100% / var(--horse-count));
  border: 2px dashed #000;
}


/* Labels & images */
.lane-label {
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: bold;
  z-index: 2;
}
.grand-derby-horse-image {
  position: absolute;
  left: 22px;       /* between number & start line */
  top: 50%;
  transform: translateY(-50%);
  max-height: 70%;
  z-index: 1;
}

/* Start & finish lines */
.grand-derby-start-line {
  position: absolute;
  top: 0; bottom: 0;
  left: 60px; 
  width: 3px;
  background: #000;
  z-index: 3;
}
.grand-derby-finish-line {
  position: absolute;
  top: 0; bottom: 0;
  left: 95%;
  width: 5px;
  background: #000;
  z-index: 3;
}
/* make the win highlight unstoppable */
.grand-derby-lane.win {
  background-color: #c8e6c9 !important;
}

.grand-derby-finish-line::after {
  content: 'Finish';
  position: absolute;
  left: -45px;   /* was calc(100% - 6px) */
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
  background: rgba(210,180,140,0.8);
  padding: 0.2em 0.4em;
  font-weight: bold;
  color: #000;
  white-space: nowrap;
}


/* Countdown overlay */
#grand-derby-countdown {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 6vw;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 0.3em 0.6em;
  border-radius: 0.3em;
  z-index: 9999;
}

/* ── Mobile centering fix ── */
@media (max-width: 600px) {
  #grand-derby {
    padding: 0.5em;       /* just a sliver of breathing room */
    margin: 0.5em auto;   /* keep it centered with small margins */
  }
}

/* When #grand-derby goes fullscreen, make it fill the screen cleanly */
#grand-derby:fullscreen {
  width: 100vw;
  height: 100vh;
}
#grand-derby:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
}
#grand-derby:-moz-full-screen {
  width: 100vw;
  height: 100vh;
}
#grand-derby:-ms-fullscreen {
  width: 100vw;
  height: 100vh;
}

/* Gray out disabled “Place Bet” button */
#grand-derby-play:disabled {
  background: #ccc !important;
  color: #666 !important;
  border-color: #aaa !important;
  cursor: not-allowed !important;
  box-shadow: none !important;
  opacity: 0.7;
}

#grand-derby-tickets {
  font-weight: bold;
  margin-top: 0.3em;
  font-size: 1em;
}

/* Desktop: keep on one line */
.grand-derby-header .header-first,
.grand-derby-header .header-second {
  display: inline;
}

/* Mobile: force second part onto its own line */
@media (max-width: 600px) {
  .grand-derby-header .header-second {
    display: block;
  }
}
