.horse-race {
  --hr-ink: #243041;
  --hr-note: #465870;
  --hr-paper: #fffdf2;
  --hr-coral: #a6432a;
  --hr-tree: #337c5a;
  --hr-far: #82abc0;
  --hr-sky: #bfe9fa;
  --hr-field: #b6d387;
  min-width: 0;
  display: grid;
  gap: .65rem;
  padding: clamp(.68rem, 2vw, 1.16rem);
  border: 1px solid #8aa88d;
  border-radius: 1rem;
  background: #eef4e4;
  color: var(--hr-ink);
  box-shadow: 0 .3rem 0 #1b38497d;
}

.horse-race[data-track='valley'] {
  --hr-far: #9f9ab9;
  --hr-sky: #d5d9f5;
  --hr-field: #b7cfac;
  --hr-tree: #537b69;
}

.horse-race[data-track='dusk'] {
  --hr-far: #9f86a7;
  --hr-sky: #ffd1ae;
  --hr-field: #d3bd83;
  --hr-tree: #6c865d;
}

.horse-race [hidden] { display: none; }
.hr-heading, .hr-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: start;
  gap: .45rem .75rem;
}

.hr-heading > div:first-child { flex: 1 1 12rem; }
.hr-heading h2 { margin: 0; color: var(--hr-ink); font-size: clamp(1.45rem, 4vw, 2.08rem); line-height: 1.08; }
.hr-heading p { margin: .32rem 0 0; color: var(--hr-note); font-size: .97rem; line-height: 1.4; }
.hr-round {
  display: grid;
  min-width: 5.4rem;
  padding: .26rem .57rem;
  border: 1px solid #9dbaa0;
  border-radius: .5rem;
  background: #fffdf2;
  font-size: .87rem;
  text-align: center;
}
.hr-round span { color: #446451; }

.hr-scene {
  isolation: isolate;
  position: relative;
  overflow: hidden;
  display: grid;
  align-items: end;
  min-height: clamp(9rem, 33vw, 13.2rem);
  border: 1px solid #527a69;
  border-radius: .78rem;
  background:
    radial-gradient(circle at 82% 15%, #fff7c3 0 5%, #fff4c184 5.4% 8%, transparent 8.6%),
    linear-gradient(180deg, var(--hr-sky), #ecf4e6 53%, var(--hr-field) 72%);
}

.hr-landscape { position: absolute; z-index: -1; inset: 0; overflow: hidden; }
.hr-landscape i { position: absolute; display: block; }
.hr-landscape i:nth-child(1) {
  inset: 17% 52% auto 9%;
  height: 9%;
  border-radius: 100% 80% 40% 50%;
  background: #fff9;
  box-shadow: 8rem .28rem 0 -.12rem #fff9, 16rem -.32rem 0 -.18rem #fffa;
}
.hr-landscape i:nth-child(2) {
  inset: 14% 0 35%;
  background: var(--hr-far);
  clip-path: polygon(0 49%,11% 15%,21% 43%,38% 3%,59% 50%,72% 13%,86% 38%,95% 5%,100% 21%,100% 100%,0 100%);
}
.hr-landscape i:nth-child(3) {
  inset: 32% -3% 23%;
  background: var(--hr-field);
  clip-path: polygon(0 26%,16% 13%,32% 26%,48% 7%,66% 19%,77% 6%,92% 23%,100% 11%,100% 100%,0 100%);
}
.hr-landscape i:nth-child(4) {
  inset: 30% -2% 31%;
  background: var(--hr-tree);
  clip-path: polygon(0 65%,4% 46%,6% 60%,10% 28%,13% 65%,17% 56%,20% 70%,25% 64%,27% 75%,32% 64%,36% 78%,42% 71%,48% 81%,53% 62%,55% 73%,61% 67%,66% 79%,71% 62%,75% 69%,81% 50%,85% 59%,92% 29%,95% 49%,100% 42%,100% 100%,0 100%);
}

.hr-track {
  --hr-horse-width: clamp(3.65rem, 17vw, 6.4rem);
  display: grid;
  border-top: 3px solid #fff6d8;
  border-bottom: 4px solid #6e4939;
  background: #bc805b;
  box-shadow: 0 -.15rem 0 #675643;
}
.hr-lane {
  --hr-position: 0%;
  display: grid;
  grid-template-columns: clamp(4.6rem, 13vw, 6.15rem) minmax(0, 1fr);
  align-items: center;
  min-height: clamp(3.05rem, 10.2vw, 4.55rem);
  background: repeating-linear-gradient(100deg, #ffedbc12 0 2px, transparent 2px 23px);
}
.hr-lane + .hr-lane { border-top: 2px dashed #f2d6a7; }
.hr-lane > span {
  width: max-content;
  max-width: 100%;
  margin-inline-start: .28rem;
  padding: .1rem .25rem;
  border-radius: .2rem;
  background: #274e59;
  color: #fff;
  text-align: center;
  font-weight: 780;
  font-size: clamp(.67rem, 1.9vw, .84rem);
  line-height: 1.24;
}
.hr-rival > span { background: #5b435d; }

.hr-runway {
  position: relative;
  align-self: stretch;
  margin-inline-end: calc(var(--hr-horse-width) + .45rem);
}
.hr-runway::after {
  content: '';
  position: absolute;
  inset: 0 auto 0 calc(100% + var(--hr-horse-width) - .35rem);
  width: .56rem;
  opacity: .75;
  background-color: #fff3d1;
  background-image: conic-gradient(#67463d 25%, transparent 0 50%, #67463d 0 75%, transparent 0);
  background-size: .56rem .56rem;
}
.hr-racer {
  position: absolute;
  z-index: 1;
  inset-block-end: -.08rem;
  inset-inline-start: var(--hr-position);
  width: var(--hr-horse-width);
  transition: inset-inline-start .24s linear;
}
.hr-racer::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: auto 10% .2rem;
  height: .43rem;
  border-radius: 50%;
  background: #5b453970;
}
.hr-horse { display: block; width: 100%; aspect-ratio: 7 / 5; object-fit: contain; }
.hr-rival .hr-horse { filter: hue-rotate(-42deg) saturate(.62) brightness(.78); }
.hr-lane[data-moving='true'] .hr-horse { animation: hr-gallop .35s ease-in-out infinite alternate; }
@keyframes hr-gallop { to { transform: translateY(-.25rem) rotate(-2deg); } }
.horse-race[data-phase='idle'] .hr-racer { transition: none; }
.horse-race[data-won='true'] .hr-scene { box-shadow: inset 0 0 0 3px #fff4b4, 0 0 0 2px #c5903e; }

.hr-hud {
  display: grid;
  grid-template-columns: 1fr 1fr .88fr .77fr;
  min-width: 0;
  gap: .35rem;
  margin: 0;
}
.hr-hud > div {
  display: grid;
  align-content: center;
  padding: .37rem .52rem;
  border: 1px solid #b3c3a8;
  border-radius: .45rem;
  background: var(--hr-paper);
}
.hr-hud dt { color: var(--hr-note); font-size: .77rem; font-weight: 800; line-height: 1.12; }
.hr-hud dd { margin: .2rem 0 0; font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.12; }
.hr-hud small { color: var(--hr-note); font-size: .69rem; font-weight: 650; }

.hr-reading { padding: clamp(.64rem, 2.4vw, 1rem); border: 1px solid #a8b8a2; border-radius: .66rem; background: var(--hr-paper); }
.hr-label { margin: 0 0 .31rem; color: #476252; font-size: .8rem; font-weight: 850; }
.hr-passage { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: clamp(1.28rem, 3.2vw, 1.72rem); line-height: 1.52; }
.hr-passage [data-status='correct'] { background: #d7efd7; color: #244832; }
.hr-passage [data-status='different'], .hr-passage [data-status='omitted'] {
  background: #f8dfa7;
  text-decoration: underline dotted #914e2d .11em;
  text-underline-offset: .17em;
}
.hr-passage .hr-current { box-shadow: 0 .12em #b96542; }

.hr-actions { justify-content: start; align-items: center; }
.hr-button {
  min-height: 2.58rem;
  padding: .39rem .71rem;
  border: 1px solid #799182;
  border-radius: .48rem;
  background: #fffdf2;
  color: #224537;
  font: inherit;
  font-weight: 770;
  text-align: center;
  cursor: pointer;
}
.hr-button[data-hr='voice'], .hr-typing .hr-button {
  border-color: #224e3b;
  background: #225943;
  color: #fff;
}
.hr-button:hover { filter: brightness(.93); }
.horse-race :is(button, textarea):focus-visible { outline: .17rem solid #a04427; outline-offset: .12rem; }
.hr-wins { margin-inline-start: auto; color: #376249; font-size: .87rem; font-weight: 850; }
.hr-typing { display: grid; gap: .38rem; }
.hr-typing label { display: grid; gap: .32rem; font-weight: 750; }
.hr-typing textarea {
  min-width: 0;
  padding: .55rem;
  border: 1px solid #799182;
  border-radius: .46rem;
  background: #fff;
  color: var(--hr-ink);
  font: inherit;
  resize: vertical;
}
.hr-typing .hr-button { justify-self: start; }
.hr-status { margin: 0; color: #354c46; font-weight: 700; line-height: 1.35; }
.horse-race[data-won='true'] .hr-status { color: #26633e; font-size: 1.07rem; }
.hr-note { color: var(--hr-note); line-height: 1.4; }

@media (max-width: 380px) {
  .hr-hud { grid-template-columns: 1fr 1fr; }
  .hr-actions { gap: .32rem; }
  .hr-button { padding-inline: .55rem; font-size: .92rem; }
}

@media (prefers-reduced-motion: reduce) {
  .hr-racer { transition: none; }
  .hr-lane[data-moving='true'] .hr-horse { animation: none; }
}
