:root {
  --race-ink: #151628;
  --race-muted: #5f6276;
  --race-panel: #ffffff;
  --race-gold: #ffc83d;
  --race-mint: #9cf2d1;
  --race-coral: #ff6f61;
  --race-blue: #37c7ff;
  --race-green: #22c55e;
  --race-shadow: 0 18px 44px rgba(21, 22, 40, 0.2);
}

* {
  box-sizing: border-box;
}

body.sphinx-race-page,
body.sphinx-race-embed {
  margin: 0;
  color: var(--race-ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 200, 61, 0.58), transparent 25%),
    radial-gradient(circle at 88% 12%, rgba(55, 199, 255, 0.45), transparent 24%),
    linear-gradient(145deg, #fff6d6 0%, #eaf7ff 52%, #e9fff8 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

body.sphinx-race-embed {
  background: transparent;
}

a {
  color: inherit;
}

.race-page-main,
.race-site-header,
.race-site-footer {
  width: min(1120px, 92vw);
  margin: 0 auto;
}

.race-site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 0 10px;
  flex-wrap: wrap;
}

.race-brand,
.race-nav a,
.race-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 900;
}

.race-brand {
  padding: 10px 16px;
  color: #ffffff;
  background: var(--race-ink);
  box-shadow: 0 4px 0 rgba(21, 22, 40, 0.24);
}

.race-nav {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.race-nav a {
  padding: 9px 13px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(21, 22, 40, 0.1);
  font-size: 0.92rem;
}

.race-page-hero {
  display: grid;
  gap: 16px;
  padding: 18px 0 10px;
}

.race-kicker {
  margin: 0 0 8px;
  color: #0f766e;
  font-size: 0.82rem;
  font-weight: 950;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.race-page-hero h1,
.race-content-section h2 {
  margin: 0;
  line-height: 1.05;
}

.race-page-hero h1 {
  max-width: 860px;
  font-size: clamp(2.1rem, 9vw, 4.25rem);
}

.race-summary {
  max-width: 780px;
  margin: 12px 0 0;
  color: var(--race-muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  font-weight: 700;
}

.race-game-shell {
  padding: 10px 0 18px;
}

.sphinx-race-embed .race-game-shell {
  padding: 0;
}

.race-game {
  width: min(100%, 1000px);
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  border: 4px solid rgba(21, 22, 40, 0.96);
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 14px 0 rgba(21, 22, 40, 0.18), 0 26px 70px rgba(21, 22, 40, 0.22);
}

.race-topbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 200, 61, 0.4), transparent 28%),
    linear-gradient(120deg, #151628, #3b215d 56%, #0f766e);
  border-bottom: 3px solid rgba(21, 22, 40, 0.9);
}

.race-stat {
  min-width: 0;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 5px 0 rgba(21, 22, 40, 0.16);
}

.race-stat:nth-child(1) {
  background: linear-gradient(145deg, #fff9c7, var(--race-gold));
}

.race-stat:nth-child(2) {
  background: linear-gradient(145deg, #dff9ff, var(--race-blue));
}

.race-stat:nth-child(3) {
  background: linear-gradient(145deg, #ffe1e5, var(--race-coral));
}

.race-stat:nth-child(4) {
  background: linear-gradient(145deg, #d9fff2, var(--race-mint));
}

.race-stat > span {
  display: block;
  color: rgba(21, 22, 40, 0.68);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.race-stat strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.05rem, 5vw, 1.55rem);
  line-height: 1;
  white-space: nowrap;
}

.race-stage {
  position: relative;
  height: clamp(500px, 72svh, 690px);
  min-height: 500px;
  overflow: hidden;
  background:
    linear-gradient(90deg, #153722 0 17%, #2f5b36 17% 23%, #20242f 23% 77%, #2f5b36 77% 83%, #153722 83% 100%);
  touch-action: none;
  cursor: pointer;
}

.race-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 52px, rgba(255, 255, 255, 0.18) 52px 92px, transparent 92px 148px),
    radial-gradient(circle at 12% 20%, rgba(255, 200, 61, 0.18), transparent 16%),
    radial-gradient(circle at 88% 40%, rgba(55, 199, 255, 0.16), transparent 18%);
  opacity: 0.75;
  animation: raceRoad 1s linear infinite;
  pointer-events: none;
}

.race-canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
}

.race-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 200, 61, 0.22), transparent 32%),
    rgba(10, 14, 32, 0.62);
  backdrop-filter: blur(5px);
}

.race-screen.is-visible {
  display: flex;
}

.race-panel {
  width: min(100%, 600px);
  padding: clamp(18px, 5vw, 32px);
  border: 4px solid rgba(21, 22, 40, 0.96);
  border-radius: 24px;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 255, 255, 0.98), transparent 28%),
    radial-gradient(circle at 82% 0%, rgba(255, 200, 61, 0.46), transparent 26%),
    linear-gradient(150deg, #ffffff 0%, #fff3bd 48%, #d9fff2 100%);
  box-shadow: 0 14px 0 rgba(21, 22, 40, 0.18), 0 24px 52px rgba(21, 22, 40, 0.2);
  text-align: center;
}

.race-game[dir="rtl"] .race-panel,
.race-game[dir="rtl"] .race-reward-panel {
  text-align: right;
}

.race-panel h1,
.race-panel h2 {
  margin: 0;
  font-size: clamp(1.95rem, 8vw, 3.2rem);
  line-height: 1;
  text-wrap: balance;
}

.race-panel p {
  margin: 12px auto 0;
  color: var(--race-muted);
  font-weight: 700;
}

.race-start-visual {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(126px, 29vw, 184px);
  margin: -8px auto 8px;
}

.race-start-visual::before {
  content: "";
  position: absolute;
  width: min(54vw, 250px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.92) 0 26%, rgba(255, 200, 61, 0.38) 27% 44%, rgba(34, 197, 94, 0.24) 45% 60%, transparent 61%);
  animation: racePrizeGlow 4s ease-in-out infinite;
}

.race-start-sphinx {
  position: relative;
  z-index: 2;
  width: clamp(126px, 32vw, 178px);
  height: auto;
  filter: drop-shadow(0 16px 12px rgba(21, 22, 40, 0.2)) drop-shadow(0 0 22px rgba(255, 200, 61, 0.44));
  animation: raceFloat 2.8s ease-in-out infinite;
}

.race-preview-token {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  min-width: 48px;
  height: 46px;
  padding: 0 9px;
  border: 2px solid #ffffff;
  border-radius: 15px;
  color: var(--race-ink);
  font-size: 0.78rem;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 7px 0 rgba(21, 22, 40, 0.16), 0 12px 22px rgba(21, 22, 40, 0.18);
}

.race-preview-token.good {
  left: 12%;
  top: 22%;
  background: linear-gradient(145deg, #fff9c7, var(--race-gold));
}

.race-preview-token.bad {
  right: 10%;
  bottom: 20%;
  color: #ffffff;
  background: linear-gradient(145deg, #6b4d91, #171923);
}

.race-subtitle {
  color: #0f766e;
  font-size: 1.05rem;
  font-weight: 950;
  text-transform: uppercase;
}

.race-rules {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 16px 0;
  padding: 0;
  list-style: none;
}

.race-rules li {
  padding: 10px 12px;
  border: 2px solid rgba(21, 22, 40, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  font-weight: 850;
}

.race-rules li:nth-child(1) {
  background: #dff9ff;
}

.race-rules li:nth-child(2) {
  background: #fff4a6;
}

.race-rules li:nth-child(3) {
  color: #ffffff;
  background: #3a2450;
}

.race-rules li:nth-child(4) {
  background: #d9fff2;
}

.race-actions,
.race-hero-actions,
.race-link-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.race-actions {
  margin-top: 18px;
}

.race-button {
  min-width: min(100%, 185px);
  border: 2px solid var(--race-ink);
  padding: 12px 18px;
  color: var(--race-ink);
  background: #ffffff;
  box-shadow: 0 5px 0 rgba(21, 22, 40, 0.2);
  cursor: pointer;
  font: inherit;
  line-height: 1.1;
  text-align: center;
}

.race-button.primary {
  background: linear-gradient(145deg, #fff78e, var(--race-gold) 54%, #ff9f1c);
}

.race-button.secondary {
  background: linear-gradient(145deg, #e8fff7, var(--race-mint));
}

.race-button.dark {
  color: #ffffff;
  background: linear-gradient(145deg, #42304a, var(--race-ink));
}

.race-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(21, 22, 40, 0.2);
}

.race-result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.race-result-card {
  padding: 14px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
}

.race-result-card span {
  display: block;
  color: var(--race-muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.race-result-card strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.6rem, 9vw, 2.7rem);
  line-height: 1;
}

.race-quote {
  padding: 12px 14px;
  border-radius: 16px;
  background: #dff9ff;
}

.race-reward-panel {
  display: none;
  margin-top: 14px;
  padding: 14px;
  border: 2px solid var(--race-ink);
  border-radius: 18px;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 200, 61, 0.62), transparent 26%),
    linear-gradient(135deg, #ffffff, rgba(156, 242, 209, 0.72));
  text-align: left;
}

.race-reward-panel.is-visible {
  display: block;
}

.race-reward-panel h3,
.race-reward-panel p {
  margin: 0;
}

.race-reward-panel h3 {
  font-size: 1.15rem;
  line-height: 1.15;
}

.race-reward-panel p + p,
.race-reward-panel h3 + p,
.race-reward-panel .race-actions {
  margin-top: 10px;
}

.race-reward-kicker {
  color: #0f766e;
  font-size: 0.75rem;
  font-weight: 950;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.race-reward-status {
  min-height: 1.4em;
  color: var(--race-muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.race-reward-locked {
  border-color: rgba(21, 22, 40, 0.22);
  background: rgba(255, 255, 255, 0.74);
}

.race-button.is-disabled,
.race-button[aria-disabled="true"] {
  opacity: 0.58;
  cursor: wait;
}

.race-live-line {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  z-index: 5;
  max-width: 540px;
  margin: 0 auto;
  padding: 9px 12px;
  color: #ffffff;
  background: rgba(21, 22, 40, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  font-size: 0.88rem;
  font-weight: 850;
  text-align: center;
  pointer-events: none;
}

.race-content-section {
  margin: 18px 0;
  padding: clamp(18px, 5vw, 28px);
  border: 1px solid rgba(21, 22, 40, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.race-content-section h2 {
  font-size: clamp(1.45rem, 5vw, 2.1rem);
}

.race-content-section p {
  max-width: 850px;
  color: var(--race-muted);
}

.race-steps {
  padding-left: 1.2rem;
  color: var(--race-muted);
  font-weight: 700;
}

.race-steps li + li {
  margin-top: 8px;
}

.race-site-footer {
  padding: 22px 0 30px;
  color: var(--race-muted);
  font-weight: 700;
}

@keyframes raceRoad {
  0% {
    background-position: 0 0, 0 0, 0 0;
  }
  100% {
    background-position: 0 148px, 0 0, 0 0;
  }
}

@keyframes raceFloat {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-7px) rotate(2deg);
  }
}

@keyframes racePrizeGlow {
  0%,
  100% {
    opacity: 0.78;
    transform: scale(0.94) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.04) rotate(10deg);
  }
}

@media (min-width: 680px) {
  .race-page-hero {
    padding-top: 28px;
  }

  .race-topbar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 12px;
  }

  .race-stat {
    padding: 10px 14px;
  }

  .race-rules {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .race-site-header {
    align-items: stretch;
  }

  .race-brand,
  .race-nav,
  .race-nav a,
  .race-button {
    width: 100%;
  }

  .race-nav {
    justify-content: stretch;
  }

  .race-stage {
    height: 74svh;
    min-height: 560px;
  }

  .race-screen {
    padding: 10px;
  }

  .race-panel {
    max-height: calc(100% - 12px);
    overflow-y: auto;
    padding: 16px 14px;
  }

  .race-panel h1,
  .race-panel h2 {
    font-size: clamp(1.55rem, 8vw, 2.1rem);
  }

  .race-rules {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin: 12px 0;
  }

  .race-rules li {
    padding: 8px 7px;
    font-size: 0.9rem;
  }

  .race-actions {
    gap: 8px;
    margin-top: 12px;
  }

  .race-button {
    min-height: 42px;
    padding: 10px 16px;
  }

  .race-start-visual {
    min-height: 126px;
  }

  .race-start-sphinx {
    width: clamp(116px, 38vw, 146px);
  }

  .race-live-line {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
