:root {
  color-scheme: dark;
  --ink: #fff8e8;
  --muted: #c7d4ce;
  --panel: rgba(9, 14, 18, 0.72);
  --line: rgba(255, 255, 255, 0.16);
  --gold: #f3c85b;
  --blue: #66a6ff;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: #071111;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 15px;
  color: #17150f;
  background: var(--gold);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.09);
  font: inherit;
  outline: none;
}

input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(243, 200, 91, 0.18);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.secondary,
.icon-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.game {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #102521;
}

.top-hud,
.race-hud,
.controls,
.help,
.leaderboard,
.shop-dialog,
.name-dialog,
.stable-dialog,
.skin-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.name-dialog {
  width: min(430px, calc(100vw - 30px));
  padding: 0;
  color: var(--ink);
}

.name-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.name-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.name-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.top-hud {
  position: absolute;
  left: 16px;
  top: 16px;
  display: grid;
  grid-template-columns: repeat(6, minmax(86px, 1fr));
  gap: 8px;
  width: min(910px, calc(100vw - 32px));
  padding: 9px;
}

.top-hud div {
  min-height: 58px;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.07);
}

.top-hud span,
.eyebrow {
  display: block;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-hud strong {
  display: block;
  margin-top: 5px;
  font-size: 0.98rem;
  overflow-wrap: anywhere;
  line-height: 1.05;
}

.race-hud {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(520px, calc(100vw - 32px));
  padding: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 3px;
  font-size: clamp(1.25rem, 2.8vw, 2.05rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.payouts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.payouts span {
  border-radius: 999px;
  padding: 7px 10px;
  color: #17150f;
  background: #fff0c5;
  font-size: 0.78rem;
  font-weight: 900;
}

.controls {
  position: absolute;
  right: 16px;
  top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(330px, calc(100vw - 32px));
  padding: 10px;
}

#startRace {
  grid-column: 1 / -1;
  min-height: 58px;
  font-size: 1.12rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.help {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  width: min(300px, calc(100vw - 32px));
  padding: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.help strong {
  color: var(--ink);
}

.leaderboard {
  position: absolute;
  right: 16px;
  top: 238px;
  width: min(330px, calc(100vw - 32px));
  padding: 12px;
  max-height: calc(100vh - 260px);
  overflow: auto;
}

#leaderboard {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style-position: inside;
}

#leaderboard li {
  min-height: 36px;
  border-radius: 7px;
  padding: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 850;
}

#leaderboard li:first-child {
  color: #17150f;
  background: var(--gold);
}

.shop-dialog,
.gear-dialog,
.skin-dialog,
.stable-dialog {
  width: min(740px, calc(100vw - 30px));
  padding: 0;
  color: var(--ink);
}

.shop-dialog::backdrop,
.gear-dialog::backdrop,
.skin-dialog::backdrop,
.stable-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.shop-dialog form,
.gear-dialog form,
.skin-dialog form,
.stable-dialog form {
  padding: 18px;
}

.shop-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

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

.stable-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 14px;
  align-items: start;
  margin-top: 16px;
}

.stable-layout .stable-list {
  margin-top: 0;
}

.equipped-horse {
  position: sticky;
  top: 0;
  display: grid;
  gap: 12px;
  min-height: 244px;
  border: 1px solid rgba(243, 200, 91, 0.5);
  border-radius: 7px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(243, 200, 91, 0.16), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.07);
}

.equipped-preview {
  min-height: 112px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 62% 26%, rgba(255, 255, 255, 0.32), transparent 15%),
    linear-gradient(160deg, rgba(243, 200, 91, 0.22), rgba(0, 0, 0, 0.18));
}

.equipped-horse h3 {
  margin: 3px 0 0;
  font-size: 1.3rem;
}

.equipped-horse p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.shop-card,
.stable-card {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.07);
}

.horse-preview {
  height: 66px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 65% 25%, rgba(255, 255, 255, 0.28), transparent 14%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.12));
  display: grid;
  place-items: center;
  font-size: 2.2rem;
}

.gear-preview {
  color: #17150f;
  background:
    radial-gradient(circle at 65% 25%, rgba(255, 255, 255, 0.38), transparent 14%),
    linear-gradient(160deg, #f3c85b, #66a6ff);
  font-size: 1.45rem;
  font-weight: 950;
  letter-spacing: 0;
}

.mini-horse {
  position: relative;
  width: 78px;
  height: 50px;
  color: var(--horse);
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.38));
}

.mini-horse-big {
  width: 160px;
  height: 102px;
  transform: translateY(4px);
}

.mini-horse span {
  position: absolute;
  display: block;
}

.mini-body {
  left: 14%;
  top: 38%;
  width: 58%;
  height: 34%;
  border-radius: 50% 45% 42% 48%;
  background: var(--horse);
}

.mini-neck {
  left: 63%;
  top: 22%;
  width: 18%;
  height: 34%;
  border-radius: 60% 60% 30% 30%;
  background: var(--horse);
  transform: rotate(-28deg);
}

.mini-head {
  left: 72%;
  top: 19%;
  width: 23%;
  height: 22%;
  border-radius: 58% 44% 48% 48%;
  background: var(--horse);
  transform: rotate(9deg);
}

.mini-ear {
  top: 8%;
  width: 8%;
  height: 17%;
  background: var(--mane);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.mini-ear-one {
  left: 73%;
  transform: rotate(-18deg);
}

.mini-ear-two {
  left: 82%;
  transform: rotate(18deg);
}

.mini-mane {
  left: 62%;
  top: 18%;
  width: 13%;
  height: 42%;
  border-radius: 70% 30% 50% 50%;
  background: var(--mane);
  transform: rotate(18deg);
}

.mini-tail {
  left: 0;
  top: 30%;
  width: 28%;
  height: 35%;
  border-radius: 80% 20% 80% 20%;
  background: var(--mane);
  transform: rotate(-24deg);
}

.mini-saddle {
  left: 33%;
  top: 34%;
  width: 25%;
  height: 17%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.38);
  background: rgba(42, 24, 16, 0.62);
}

.mini-leg {
  top: 67%;
  width: 8%;
  height: 31%;
  border-radius: 999px;
  background: color-mix(in srgb, var(--horse) 72%, #000);
}

.mini-leg::after {
  content: "";
  position: absolute;
  left: -22%;
  bottom: -7%;
  width: 140%;
  height: 18%;
  border-radius: 999px;
  background: #160c08;
}

.mini-leg-one {
  left: 22%;
  transform: rotate(8deg);
}

.mini-leg-two {
  left: 40%;
  transform: rotate(-5deg);
}

.mini-leg-three {
  left: 58%;
  transform: rotate(7deg);
}

.mini-leg-four {
  left: 72%;
  transform: rotate(-7deg);
}

.mini-crown {
  left: 75%;
  top: -9%;
  width: 18%;
  height: 20%;
  background: #f8d65a;
  clip-path: polygon(0 100%, 0 28%, 24% 66%, 50% 0, 76% 66%, 100% 28%, 100% 100%);
}

.mini-crown::after {
  content: "";
  position: absolute;
  left: 18%;
  bottom: 8%;
  width: 64%;
  height: 18%;
  border-radius: 999px;
  background: #fff3a3;
}

.shop-card h3,
.stable-card h3 {
  margin: 0;
  font-size: 1rem;
}

.shop-card p,
.stable-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.shop-card button,
.stable-card button {
  width: 100%;
  margin-top: 9px;
}

@media (max-width: 820px) {
  body {
    overflow-y: auto;
  }

  .game {
    min-height: 100vh;
    height: 100svh;
  }

  .top-hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls {
    top: auto;
    bottom: 16px;
    right: 16px;
  }

  .race-hud {
    bottom: 126px;
  }

  .leaderboard,
  .help {
    display: none;
  }

  .shop-list,
  .stable-list {
    grid-template-columns: 1fr;
  }

  .stable-layout {
    grid-template-columns: 1fr;
  }
}
