/* Shared styles for race-engine powered pages: race-timer, and all themed race skins */
.track{
  border: 1px solid var(--line); border-radius: 16px; overflow-x:hidden; overflow-y:auto;
  margin-top: 18px; max-height: 640px;
}
.lane{ position:relative; height: 88px; display:flex; align-items:center; border-bottom: 1px solid rgba(255,255,255,0.06); }
.lane:last-child{ border-bottom:none; }
.lane:nth-child(odd){ background: var(--lane-alt); }
.lane-track{ position:relative; flex:1; height:100%; margin: 0 8px; }
.rail{ position:absolute; top:50%; left:0; right:44px; height:2px; transform: translateY(-1px);
  background: repeating-linear-gradient(90deg, var(--line) 0 10px, transparent 10px 20px); }
.flag{ position:absolute; right:0; top:12px; bottom:12px; width:18px; border-radius:4px;
  background-image: repeating-conic-gradient(#111 0 25%, #f5f0e6 0 50%); background-size: 9px 9px; opacity:.85; }

/* --- Illustrated runner character: name tag + colored body + animated legs --- */
.runner-wrap{
  position:absolute; top:50%; transform: translate(0,-50%);
  width: 92px; display:flex; flex-direction:column; align-items:center; gap:3px;
  z-index: 2;
}
.runner-name-tag{
  font-size: 15px; font-weight: 800; color: var(--cream);
  background: rgba(0,0,0,.55); padding: 3px 9px; border-radius: 8px;
  white-space: nowrap; max-width: 92px; overflow: hidden; text-overflow: ellipsis;
}
.runner-body{
  width: 56px; height: 56px; border-radius: 50%;
  display:flex; align-items:center; justify-content:center;
  font-size: 23px; font-weight: 800; color:#101418;
  box-shadow: 0 3px 7px rgba(0,0,0,.4);
}
.runner-body.emoji{ font-size: 32px; background: rgba(255,255,255,0.06) !important; }
.runner-body.custom{
  width: auto; height: auto; border-radius: 0; box-shadow: none; background: none !important;
  display: block;
}
.runner-body.image{
  width: 64px; height: 64px; border-radius: 0; box-shadow: none; background: none !important;
  object-fit: contain;
}
.runner-body.image.flip-x{ transform: scaleX(-1); } /* only for source art that faces the wrong way by default */
.lane.finished .runner-body.custom{ box-shadow: none; transform: scale(1.12); border-radius: 10px; }
.lane.finished .runner-body.custom svg{ filter: drop-shadow(0 0 4px var(--gold)); }
.lane.finished .runner-body.image{ transform: scale(1.15); filter: drop-shadow(0 0 5px var(--gold)); }
.lane.finished .runner-body.image.flip-x{ transform: scaleX(-1) scale(1.15); filter: drop-shadow(0 0 5px var(--gold)); }

.runner-wrap.running .runner-body{ animation: run-bob 0.42s ease-in-out infinite; }
@keyframes run-bob{
  0%, 100%{ transform: translateY(0) rotate(0deg); }
  50%{ transform: translateY(-5px) rotate(-6deg); }
}
.runner-wrap.running .runner-body.image.flip-x{ animation: run-bob-flipped 0.42s ease-in-out infinite; }
@keyframes run-bob-flipped{
  0%, 100%{ transform: scaleX(-1) translateY(0) rotate(0deg); }
  50%{ transform: scaleX(-1) translateY(-5px) rotate(6deg); }
}

.runner-body.finished-bounce{ animation: finish-bounce 0.5s cubic-bezier(.34,1.56,.64,1); }
@keyframes finish-bounce{
  0%{ transform: scale(1); }
  40%{ transform: scale(1.35) rotate(8deg); }
  100%{ transform: scale(1.1) rotate(0deg); }
}
.runner-body.image.flip-x.finished-bounce{ animation: finish-bounce-flipped 0.5s cubic-bezier(.34,1.56,.64,1); }
@keyframes finish-bounce-flipped{
  0%{ transform: scaleX(-1) scale(1); }
  40%{ transform: scaleX(-1) scale(1.35) rotate(-8deg); }
  100%{ transform: scaleX(-1) scale(1.1) rotate(0deg); }
}
.lane.finished .runner-body{
  transform: scale(1.1);
  box-shadow: 0 0 0 3px var(--gold), 0 2px 5px rgba(0,0,0,.35);
}
.rank-badge{ position:absolute; left: -26px; top:50%; transform: translateY(-50%);
  font-family:'Archivo Black', sans-serif; font-size: 12px; color: var(--gold); opacity:0; transition: opacity .2s ease; }
.lane.finished .rank-badge{ opacity:1; }

.race-countdown-overlay{
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,14,22,.55); backdrop-filter: blur(1px);
  font-family: 'Archivo Black', sans-serif;
  font-size: clamp(32px, 7vw, 56px);
  color: var(--gold);
  border-radius: 16px;
}
.race-countdown-overlay.pulse{ animation: countdown-pulse 0.55s ease-out; }
@keyframes countdown-pulse{
  0%{ transform: scale(0.5); opacity: 0; }
  40%{ transform: scale(1.15); opacity: 1; }
  100%{ transform: scale(1); opacity: 1; }
}

.confetti-particle{
  position: absolute; width: 6px; height: 6px; border-radius: 2px;
  pointer-events: none; z-index: 6;
  animation: confetti-burst 0.65s ease-out forwards;
}
@keyframes confetti-burst{
  0%{ transform: translate(0,0) rotate(0deg); opacity: 1; }
  100%{ transform: translate(var(--dx), calc(var(--dy) + 20px)) rotate(220deg); opacity: 0; }
}

textarea{ width:100%; min-height: 150px; resize: vertical; background: #0f1522; color: var(--cream);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-family:'Work Sans', sans-serif;
  font-size:14px; line-height:1.6; outline: none; }
textarea:focus{ border-color: var(--gold); }
.row{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; justify-content:space-between; margin-top: 14px; }
.count{ color: var(--cream-dim); font-size:13px; }

.race-controls{ display:flex; justify-content:center; margin-top: 4px; }

.leaderboard{ margin-top: 22px; }
.leaderboard h3{ font-size:12px; letter-spacing:2px; color: var(--cream-dim); text-transform:uppercase; margin: 0 0 10px; }
.lb-item{ display:flex; align-items:center; gap:12px; padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.02); margin-bottom: 6px; animation: pop .25s ease; }
@keyframes pop{ from{ transform: scale(.92); opacity:0; } to{ transform:scale(1); opacity:1; } }
.lb-rank{ font-family:'Archivo Black', sans-serif; color: var(--gold); width: 28px; }
.lb-name{ font-weight:700; }

.related-skins{ margin-top: 40px; }
.race-banner{
  width: 100%; height: 150px; object-fit: cover; display: block;
  border-radius: 16px 16px 0 0; margin-top: 18px;
}
.race-banner + .track{ margin-top: 0; border-radius: 0 0 16px 16px; }
.related-skins h3{ font-size:12px; letter-spacing:2px; color: var(--cream-dim); text-transform:uppercase; margin: 0 0 12px; text-align:center; }
.skin-links{ display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
.skin-links a{ text-decoration:none; background: var(--panel-bg); border:1px solid var(--line); border-radius:10px;
  padding: 10px 16px; font-size:13px; font-weight:700; }
.skin-links a:hover{ border-color: var(--gold); }

/* =====================================================================
   Scene layout (opt-in): background art fills the whole race area and
   every lane always fits on screen. Used by every race-engine page.
   Pages without background art use <div class="race-stage"> (no "scene").
   Markup:
     <div class="race-stage scene" style="--scene-bg:url('../img/bg-ninja-race.jpg')">
       <div class="finish-label">Finish</div>
       <div class="track fit-lanes" id="track"></div>
     </div>
   ===================================================================== */
.race-stage{
  --sky: clamp(56px, 11vh, 110px);
  position: relative; margin-top: 18px; border-radius: 16px; overflow: hidden;
  border: 1px solid var(--line);
  height: clamp(420px, 72vh, 780px);
  padding-top: var(--sky);
  display: flex; flex-direction: column;
  background:
    linear-gradient(rgba(10,8,20,0) 0%, rgba(10,8,20,.3) 30%, rgba(10,8,20,.6) 100%),
    var(--scene-bg, none) center top / cover no-repeat,
    var(--track-bg, #16121c);
}
body.fs-active .race-stage{ height: calc(100vh - 150px); }
/* stages without background art just need room for the Finish label */
.race-stage:not(.scene){ --sky: 44px; }

.race-stage .finish-label{
  position: absolute; right: 4px; top: calc(var(--sky) - 30px); z-index: 3;
  background: #d8413a; color: #fff; font-family: 'Archivo Black', sans-serif; font-size: 13px;
  padding: 4px 10px; border-radius: 6px 6px 0 6px; box-shadow: 0 3px 8px rgba(0,0,0,.4);
}

.track.fit-lanes{
  flex: 1; min-height: 0; max-height: none; margin: 0;
  border: none; border-radius: 0; overflow: visible;
  display: flex; flex-direction: column; background: transparent;
}
.track.fit-lanes .lane{
  flex: 1 1 0; height: auto; min-height: 0;
  border-bottom: none; border-top: 1px solid rgba(255,255,255,.14);
}
.track.fit-lanes .lane:last-child{ border-bottom: 1px solid rgba(255,255,255,.14); }
.track.fit-lanes .lane:nth-child(odd){ background: rgba(16,11,32,.5); }
.track.fit-lanes .lane:nth-child(even){ background: rgba(28,20,52,.38); }

/* one finish line across every lane (replaces the per-lane flags) */
.track.fit-lanes .flag{ display: none; }
.track.fit-lanes::after{
  content: ""; position: absolute; top: 0; bottom: 0; right: 8px; width: 16px; z-index: 1;
  background-image: repeating-conic-gradient(#111 0 25%, #f5f0e6 0 50%); background-size: 16px 16px;
  box-shadow: 0 0 10px rgba(0,0,0,.6); pointer-events: none;
}
/* start line */
.track.fit-lanes::before{
  content: ""; position: absolute; top: 0; bottom: 0; left: calc(8px + var(--start-x, 80px)); width: 2px;
  background: rgba(255,255,255,.35); z-index: 1; pointer-events: none;
}
.track.fit-lanes .rail{ left: var(--start-x, 80px); right: 0; opacity: .45; }
.track.fit-lanes .rank-badge{ display: none; }

/* runners scale with the lane; name tag rides just behind the runner */
.track.fit-lanes .runner-wrap{
  display: block; width: auto; height: var(--runner-size, 56px); gap: 0;
}
.track.fit-lanes .runner-name-tag{
  position: absolute; right: 100%; top: 50%; transform: translateY(-50%); margin-right: 4px;
  font-size: var(--label-size, 15px); padding: .15em .6em; border-radius: 999px;
  max-width: calc(var(--start-x, 80px) - 8px); background: rgba(10,8,20,.8);
  border: 1px solid rgba(255,255,255,.18);
}
.track.fit-lanes .lane.finished .runner-name-tag{ max-width: none; }
.track.fit-lanes .tag-rank{ color: var(--gold); margin-right: .2em; }
/* images: same height for every character, width follows the artwork */
.track.fit-lanes .runner-body.image{
  height: 100%; width: auto; max-width: none;
  filter: drop-shadow(0 0 1.5px rgba(255,255,255,.7)) drop-shadow(0 3px 3px rgba(0,0,0,.5));
}
.track.fit-lanes .lane.finished .runner-body.image{
  box-shadow: none; transform: scale(1.05);
  filter: drop-shadow(0 0 2px var(--gold)) drop-shadow(0 0 6px var(--gold));
}
.track.fit-lanes .runner-body.image.finished-bounce{ animation: none; }
/* emoji / initials bodies (if another skin opts in) */
.track.fit-lanes .runner-body:not(.image):not(.custom){
  width: var(--runner-size, 56px); height: var(--runner-size, 56px);
  font-size: calc(var(--runner-size, 56px) * 0.45);
}
