/* High Five Racers. What's special to this game: who's where, the turbo meter, and little words. */

body:not([data-screen='playing']) .turbo,
body:not([data-screen='playing']) .toast,
body:not([data-screen='playing']) .five-film { display: none; }

/* ---------- who's in front: faces in order, which swap places when someone overtakes ---------- */
.race-order {
  --row: clamp(38px, 6.4vh, 52px);
  position: relative;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  width: calc(var(--row) * 1.75);
  height: calc(var(--row) * 4);
}

.order-row {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
  height: calc(var(--row) - 4px);
  padding: 2px 4px 2px 8px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(18, 48, 77, 0.18);
  transform: translateY(calc(var(--slot, 0) * var(--row)));
  transition: transform 0.35s ease-out;
}

.order-row img {
  height: 100%;
  aspect-ratio: 1;
  margin-left: auto;
  border-radius: 50%;
  background: #dff1ff;
  object-fit: cover;
}

.order-number {
  font-size: clamp(13px, 1.6vw, 19px);
  font-weight: 700;
  color: var(--ink-soft);
}

.order-row.is-you {
  background: var(--sun);
  box-shadow: 0 3px 12px rgba(219, 165, 0, 0.5);
}

.order-row.is-you .order-number { color: var(--ink); }

/* ---------- the turbo meter ---------- */
.turbo {
  position: fixed;
  z-index: 2;
  bottom: 14px;
  left: calc(50% + (var(--meter-size) + clamp(8px, 2vw, 24px) + clamp(46px, 6vw, 74px)) / 2 + 12px);
  display: flex;
  align-items: center;
  gap: 8px;
  width: clamp(180px, 25vw, 330px);
  padding: 8px 14px 8px 10px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.turbo-flame {
  flex: none;
  width: clamp(30px, 3.6vw, 46px);
  height: auto;
  fill: #b7c3cf;
  transform-origin: 50% 90%;
}

.turbo-flame-core { fill: #e6ecf1; }

.turbo-parts {
  flex: 1;
  display: grid;
  gap: 5px;
  min-width: 0;
}

.turbo-words {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  line-height: 1;
}

.turbo-word { font-size: clamp(16px, 2vw, 25px); }

.turbo-speed {
  font-size: clamp(15px, 1.8vw, 22px);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.turbo-track {
  height: clamp(12px, 1.7vw, 20px);
  background: var(--accent-track);
  border-radius: 999px;
  overflow: hidden;
}

.turbo-fill {
  height: 100%;
  background: linear-gradient(90deg, #ffb703, #ff7a1f);
  border-radius: 999px;
  transform: scaleX(0);
  transform-origin: left;
}

.turbo[data-state='filling'] .turbo-flame { fill: #ffb703; }
.turbo[data-state='filling'] .turbo-flame-core { fill: #ffe7a0; }

/* Turbo: a bigger flame and a coloured frame, in steady colours. Nothing here blinks. */
.turbo[data-state='on'] {
  box-shadow: 0 0 0 4px #ff7a1f, var(--shadow);
}

.turbo[data-state='on'] .turbo-flame {
  fill: #ff7a1f;
  animation: turbo-flame 0.9s ease-in-out infinite;
}

.turbo[data-state='on'] .turbo-flame-core { fill: #ffd84a; }
.turbo[data-state='on'] .turbo-word { color: #d9520a; }

@keyframes turbo-flame {
  0%, 100% { transform: scale(1.12) rotate(-3deg); }
  50% { transform: scale(1.28) rotate(3deg); }
}

.turbo.is-hint { animation: turbo-hint 1.2s ease-in-out infinite; }

@keyframes turbo-hint {
  50% { transform: translateY(-6px) scale(1.04); }
}

/* ---------- little words beside the action ---------- */
.toast {
  position: fixed;
  z-index: 3;
  left: 50%;
  top: 34%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 22px 8px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: clamp(20px, 3vw, 36px);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 0);
  pointer-events: none;
}

.toast.is-showing { animation: toast 1.5s ease-out both; }

.toast-face {
  width: clamp(36px, 4vw, 52px);
  height: clamp(36px, 4vw, 52px);
  margin-left: -14px;
  border-radius: 50%;
  background: #dff1ff;
  object-fit: cover;
}

.toast-face.is-hidden { display: none; }

@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(0.8); }
  14% { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  24% { transform: translate(-50%, 0) scale(1); }
  76% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(1); }
}

/* ---------- a little film: an open hand going over to the big one, and slapping it ---------- */
.five-film {
  display: none;
  position: fixed;
  z-index: 3;
  left: 16px;
  bottom: 16px;
  width: min(19vw, 30vh);
  min-width: 110px;
  background: linear-gradient(#cfeeff, #f4fbff);
  border: 5px solid var(--sun);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

body[data-screen='playing'][data-five-film] .five-film { display: block; }
body[data-five-film='left'] .five-film svg { transform: scaleX(-1); }
.five-film svg { display: block; width: 100%; height: auto; }

.five-film path,
.five-film rect { stroke-linecap: round; stroke-linejoin: round; }

.five-film-big rect { fill: #ffd23f; stroke: var(--ink); stroke-width: 2.5; }
.five-film-big path { fill: none; stroke: #ffd23f; stroke-width: 8; }
.five-film-small rect { fill: var(--good); stroke: var(--ink); stroke-width: 2; }
.five-film-small path { fill: none; stroke: var(--good); stroke-width: 6; }
.five-film-burst path { fill: #ff7a1f; stroke: var(--ink); stroke-width: 2; }

.five-film-small { animation: film-reach 2.2s ease-in infinite; }
.five-film-big { transform-box: fill-box; transform-origin: 50% 100%; animation: film-swing 2.2s ease-out infinite; }
.five-film-burst { transform-box: fill-box; transform-origin: center; animation: film-burst 2.2s ease-out infinite; }

@keyframes film-reach {
  0%, 10% { transform: translate(0, 0); }
  58%, 70% { transform: translate(34px, -8px); }
  100% { transform: translate(0, 0); }
}

@keyframes film-swing {
  0%, 56% { transform: rotate(0); }
  64% { transform: rotate(16deg); }
  76% { transform: rotate(-5deg); }
  88%, 100% { transform: rotate(0); }
}

@keyframes film-burst {
  0%, 56% { opacity: 0; transform: scale(0.3); }
  62% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: scale(1.15); }
  92%, 100% { opacity: 0; transform: scale(1.3); }
}

@media (max-height: 560px) {
  .race-order { --row: clamp(28px, 9vh, 38px); }
}

@media (max-width: 700px) {
  .turbo {
    left: auto;
    right: 10px;
    bottom: calc(var(--meter-size) + 54px);
    width: 170px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .order-row { transition: none; }
  .turbo.is-hint,
  .turbo[data-state='on'] .turbo-flame { animation: none; }
  .toast.is-showing { animation-name: toast-still; }
  .five-film-small,
  .five-film-big,
  .five-film-burst { animation-duration: 3.4s; }
}

@keyframes toast-still {
  0%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}
