body {
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

.setup-nav {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 24px 0;
}

#setup {
  max-width: 780px;
  margin: 0 auto;
  padding: 30px 24px 64px;
}

.setup-header {
  text-align: center;
  margin-bottom: 34px;
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.setup-title {
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  font-weight: 850;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #fbbf24 0%, #38bdf8 52%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.setup-sub {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
  max-width: 560px;
  margin: 0 auto;
}

.panel,
.rank-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.panel {
  padding: 22px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.panel-help {
  color: #6868aa;
  font-size: 0.78rem;
  margin-top: 4px;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) minmax(140px, 220px) 32px;
  align-items: center;
  gap: 10px;
}

.color-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.entry-input,
.horse-select {
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.entry-input {
  padding: 10px 12px;
}

.horse-select {
  padding: 10px;
  cursor: pointer;
}

.entry-input::placeholder {
  color: #3a3a70;
}

.entry-input:focus,
.horse-select:focus {
  border-color: var(--accent);
}

.btn-load-team,
.btn-add,
.btn-nav,
.btn-modal {
  font-family: inherit;
}

.btn-load-team,
.btn-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-load-team {
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.btn-load-team.has-team {
  color: var(--accent-light);
  border-color: rgba(167, 139, 250, 0.45);
  background: rgba(167, 139, 250, 0.08);
}

.btn-nav {
  padding: 8px 15px;
  display: inline-flex;
  align-items: center;
  font-size: 0.85rem;
}

.btn-load-team:hover,
.btn-nav:hover {
  color: var(--accent-light);
  border-color: var(--accent);
}

.btn-x {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #3f3f78;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}

.btn-x:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.08);
}

.btn-add {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.86rem;
  cursor: pointer;
}

.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}

.count-note {
  text-align: center;
  color: var(--muted);
  min-height: 22px;
  margin: 14px 0;
  font-size: 0.84rem;
}

.count-note.warn {
  color: #fb923c;
}

.btn-start {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  background: linear-gradient(135deg, #f59e0b 0%, #06b6d4 100%);
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.12s;
}

.btn-start:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

#race {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px;
  gap: 14px;
}

.race-nav {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-logo {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fbbf24, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-btns {
  display: flex;
  gap: 8px;
}

.scorebar {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scorebar > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.scorebar strong {
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}

.track-wrap {
  position: relative;
  flex: 1;
  min-height: 560px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 72px),
    linear-gradient(180deg, #1e2b2a 0%, #15192d 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.lanes {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.lane {
  position: relative;
  flex: 1;
  min-height: 76px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.13);
  overflow: hidden;
}

.lane:last-child {
  border-bottom: none;
}

.lane::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(251,191,36,0.08), transparent 28%, rgba(56,189,248,0.06));
  opacity: 0.72;
}

.lane-label {
  position: absolute;
  top: 8px;
  left: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(34vw, 360px);
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(12, 12, 26, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lane-label span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lane-number {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #0c0c1a;
  font-size: 0.68rem;
  flex-shrink: 0;
}

.runner {
  position: absolute;
  left: 10px;
  top: 50%;
  --runner-scale: 1;
  width: 126px;
  height: 78px;
  transform: translate3d(0, -42%, 0) scale(var(--runner-scale));
  transition: transform 0.12s linear;
  z-index: 3;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,0.34));
  transform-origin: left center;
}

.horse {
  position: absolute;
  inset: 0;
  transform-origin: center;
  animation: gallop 0.36s linear infinite;
}

.horse-body,
.horse-neck,
.horse-head,
.horse-tail,
.leg,
.ear,
.muzzle,
.mane,
.saddle,
.mark {
  position: absolute;
}

.horse-body {
  width: 74px;
  height: 29px;
  left: 26px;
  top: 28px;
  border-radius: 55% 48% 43% 47%;
  background: var(--coat);
}

.horse-neck {
  width: 17px;
  height: 39px;
  left: 88px;
  top: 6px;
  border-radius: 13px 13px 7px 7px;
  background: var(--coat);
  transform: rotate(-32deg);
}

.horse-head {
  width: 31px;
  height: 18px;
  left: 96px;
  top: 5px;
  border-radius: 55% 38% 48% 34%;
  background: var(--coat);
  transform: rotate(5deg);
}

.horse-head::after {
  content: '';
  position: absolute;
  right: 9px;
  top: 5px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #080812;
}

.ear {
  width: 7px;
  height: 15px;
  left: 100px;
  top: -3px;
  border-radius: 8px 8px 2px 2px;
  background: var(--coat);
  transform: rotate(-18deg);
}

.ear::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 13px;
  left: 8px;
  top: 1px;
  border-radius: 8px 8px 2px 2px;
  background: var(--coat);
  transform: rotate(24deg);
}

.muzzle {
  width: 15px;
  height: 10px;
  left: 116px;
  top: 14px;
  border-radius: 0 999px 999px 35%;
  background: var(--coat);
  box-shadow: inset 5px 0 0 rgba(255, 255, 255, 0.18);
}

.muzzle::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 4px;
  width: 3px;
  height: 2px;
  border-radius: 50%;
  background: #111827;
}

.mane {
  width: 10px;
  height: 39px;
  left: 86px;
  top: 6px;
  border-radius: 9px;
  background: var(--mane);
  transform: rotate(-31deg);
}

.horse-tail {
  width: 38px;
  height: 10px;
  left: -8px;
  top: 31px;
  border-radius: 999px 20% 20% 999px;
  background: var(--mane);
  transform-origin: right center;
  animation: tail 0.36s ease-in-out infinite;
}

.saddle {
  width: 28px;
  height: 13px;
  left: 53px;
  top: 24px;
  border-radius: 4px 4px 8px 8px;
  background: var(--saddle);
  border: 2px solid rgba(255,255,255,0.25);
}

.mark {
  width: 6px;
  height: 14px;
  left: 106px;
  top: 6px;
  border-radius: 999px;
  background: var(--mark);
  opacity: 0.9;
}

.leg {
  width: 6px;
  height: 34px;
  top: 52px;
  border-radius: 5px;
  background: var(--leg);
  transform-origin: top center;
}

.leg::after {
  content: '';
  position: absolute;
  left: -2px;
  bottom: -2px;
  width: 14px;
  height: 5px;
  border-radius: 999px;
  background: #080812;
}

.leg.front-a { left: 86px; animation: legFront 0.36s linear infinite; }
.leg.front-b { left: 96px; animation: legBack 0.36s linear infinite; }
.leg.back-a { left: 36px; animation: legBack 0.36s linear infinite; }
.leg.back-b { left: 50px; animation: legFront 0.36s linear infinite; }

.finish-line {
  position: absolute;
  top: 0;
  right: 54px;
  width: 18px;
  height: 100%;
  z-index: 1;
  background:
    linear-gradient(45deg, #fff 25%, #111 25% 50%, #fff 50% 75%, #111 75%) 0 0 / 18px 18px;
  opacity: 0.8;
  box-shadow: 0 0 24px rgba(255,255,255,0.22);
}

.rank-panel {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px;
}

#rank-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

#rank-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  min-width: 0;
}

.rank-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 850;
  flex-shrink: 0;
}

.rank-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 18, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.modal-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid #2a2a5a;
  border-radius: 20px;
  padding: 28px 24px 24px;
  transform: scale(0.94) translateY(10px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.visible .modal {
  transform: scale(1) translateY(0);
}

.modal-title {
  font-size: 1.32rem;
  font-weight: 850;
  text-align: center;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
  color: #fbbf24;
}

.modal-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 18px;
}

.winner-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.winner-name {
  display: block;
  font-size: 1.2rem;
  font-weight: 850;
  color: #fbbf24;
  margin-bottom: 3px;
}

.winner-meta {
  color: var(--text);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.btn-modal {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.875rem;
  font-weight: 750;
  cursor: pointer;
}

.btn-modal.secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.btn-modal.primary {
  background: linear-gradient(135deg, #f59e0b, #06b6d4);
  color: #fff;
}

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

@keyframes legFront {
  0%, 100% { transform: rotate(24deg); }
  50% { transform: rotate(-34deg); }
}

@keyframes legBack {
  0%, 100% { transform: rotate(-28deg); }
  50% { transform: rotate(30deg); }
}

@keyframes tail {
  0%, 100% { transform: rotate(14deg); }
  50% { transform: rotate(-12deg); }
}

@media (max-width: 680px) {
  .entry-row {
    grid-template-columns: 8px minmax(0, 1fr) 32px;
  }

  .horse-select {
    grid-column: 2 / 3;
  }

  .race-nav {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .game-logo {
    order: -1;
    flex-basis: 100%;
  }

  .nav-btns {
    margin-left: auto;
  }

  .track-wrap {
    min-height: 560px;
  }

  .lane-label {
    max-width: 58vw;
    font-size: 0.72rem;
  }

  .runner {
    --runner-scale: 0.78;
  }

  .finish-line {
    right: 34px;
  }
}

@media (max-width: 460px) {
  #setup {
    padding-inline: 18px;
  }

  .panel {
    padding: 18px;
  }

  .panel-header,
  .scorebar {
    grid-template-columns: 1fr;
  }

  .scorebar {
    display: grid;
  }

  .modal-actions {
    flex-direction: column;
  }
}
