:root {
  color-scheme: dark;
  --ink: #18120f;
  --paper: #fff7df;
  --panel: rgba(34, 24, 20, 0.8);
  --panel-strong: rgba(22, 16, 14, 0.92);
  --line: rgba(255, 247, 223, 0.22);
  --gold: #f6b34d;
  --aqua: #4ecdc4;
  --rose: #ff6b6b;
  --sage: #90be6d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #170f14;
  color: var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body.screen-menu,
body.screen-ended {
  overflow: auto;
}

button,
input,
select {
  font: inherit;
}

.main-menu {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(280px, 1.1fr);
  align-items: center;
  gap: 30px;
  overflow: auto;
  padding: clamp(18px, 3.8vw, 58px);
  background:
    radial-gradient(circle at 43% 76%, rgba(255, 239, 170, 0.72), transparent 17%),
    radial-gradient(circle at 96% 84%, rgba(60, 34, 25, 0.5), transparent 4%),
    radial-gradient(circle at 2% 88%, rgba(60, 34, 25, 0.45), transparent 4%),
    linear-gradient(180deg, #2a120f 0%, #641b14 30%, #d44d22 60%, #eeb31e 84%, #f4c34d 100%);
}

.main-menu[hidden] {
  display: none;
}

.main-menu::before,
.main-menu::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.main-menu::before {
  bottom: 26%;
  height: 24%;
  background: #4d331b;
  clip-path: polygon(0 62%, 8% 54%, 15% 62%, 24% 49%, 38% 61%, 48% 52%, 58% 63%, 68% 51%, 80% 62%, 92% 55%, 100% 63%, 100% 100%, 0 100%);
}

.main-menu::after {
  bottom: 17%;
  height: 16%;
  background: #351d18;
  clip-path: polygon(0 35%, 8% 22%, 17% 40%, 28% 24%, 39% 39%, 50% 23%, 61% 42%, 73% 27%, 86% 39%, 100% 24%, 100% 100%, 0 100%);
}

.menu-copy,
.menu-figure {
  position: relative;
  z-index: 1;
}

.menu-kicker,
.menu-group > span {
  margin: 0 0 12px;
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

.menu-copy h1 {
  max-width: 640px;
  margin: 0;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.2rem, 7vw, 6.8rem);
  font-weight: 900;
  line-height: 0.86;
  text-shadow: 0 7px 0 rgba(31, 13, 9, 0.34);
}

.menu-copy h1 span {
  display: block;
  color: var(--paper);
}

.menu-lede {
  max-width: 560px;
  margin: 22px 0 22px;
  color: rgba(255, 247, 223, 0.88);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.98rem, 1.35vw, 1.25rem);
  font-style: italic;
  font-weight: 700;
  line-height: 1.35;
}

.menu-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 10px;
  max-width: 520px;
  margin: 0 0 16px;
}

.menu-stats div {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(30, 17, 13, 0.56);
}

.menu-stats span,
.store-head span {
  color: rgba(255, 247, 223, 0.72);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.menu-stats strong,
.store-head strong {
  color: var(--gold);
  font-size: 1.02rem;
}

.menu-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 640px;
  margin: 0 0 14px;
}

.menu-tab {
  min-height: 42px;
  border: 1px solid rgba(255, 247, 223, 0.22);
  background: rgba(34, 19, 14, 0.68);
  color: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(255, 247, 223, 0.06);
  text-transform: uppercase;
}

.menu-tab.selected {
  background: #9c211c;
  border-color: var(--gold);
}

.menu-page {
  display: none;
  max-width: 900px;
}

.menu-page.selected {
  display: grid;
  gap: 12px;
}

.menu-group {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.menu-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.difficulty-card,
.mode-card {
  min-width: 150px;
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 7px;
  border: 2px solid rgba(27, 14, 10, 0.58);
  background: rgba(72, 40, 22, 0.82);
  color: var(--paper);
  box-shadow: inset 0 0 0 2px rgba(255, 247, 223, 0.08), 0 6px 0 rgba(22, 10, 7, 0.45);
  font-family: Georgia, "Times New Roman", serif;
  text-transform: uppercase;
}

.difficulty-card strong,
.mode-card strong {
  font-size: 1.06rem;
}

.difficulty-card small,
.mode-card small {
  color: rgba(255, 247, 223, 0.82);
  font-size: 0.72rem;
  font-weight: 900;
}

.difficulty-card.selected,
.mode-card.selected {
  background: #9c211c;
  border-color: var(--gold);
}

.level-options {
  display: grid;
  grid-template-columns: repeat(10, minmax(40px, 1fr));
  gap: 7px;
  max-width: 560px;
}

.level-button {
  min-width: 0;
  min-height: 42px;
  padding: 0;
  border: 1px solid rgba(27, 14, 10, 0.58);
  background: rgba(72, 40, 22, 0.82);
  color: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(255, 247, 223, 0.08), 0 4px 0 rgba(22, 10, 7, 0.42);
}

.level-button.selected {
  background: #9c211c;
  border-color: var(--gold);
}

.level-button:disabled {
  background: rgba(22, 13, 11, 0.72);
  color: rgba(255, 247, 223, 0.48);
  box-shadow: none;
}

.store-panel {
  max-width: 820px;
}

.store-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.horse-store {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 10px;
}

.horse-card {
  min-height: 132px;
  display: grid;
  align-content: space-between;
  gap: 9px;
  padding: 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
  color: var(--paper);
  text-align: left;
}

.horse-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(246, 179, 77, 0.28);
}

.horse-card.locked {
  background: rgba(22, 13, 11, 0.7);
}

.horse-card strong {
  display: block;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

.horse-card small {
  display: block;
  color: rgba(255, 247, 223, 0.8);
  font-size: 0.78rem;
  line-height: 1.25;
}

.horse-card span {
  color: var(--paper);
  font-size: 0.82rem;
  font-weight: 900;
}

.upgrade-panel {
  max-width: 900px;
}

.upgrade-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 8px;
}

.upgrade-summary div,
.upgrade-card,
.pre-start-details div,
.pre-start-upgrades div {
  border: 1px solid rgba(255, 247, 223, 0.18);
  border-radius: 8px;
  background: rgba(24, 15, 12, 0.62);
}

.upgrade-summary div {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
}

.upgrade-summary span,
.upgrade-card span,
.pre-start-details span,
.pre-start-upgrades span {
  color: rgba(255, 247, 223, 0.7);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.upgrade-summary strong,
.upgrade-card strong,
.pre-start-details strong,
.pre-start-upgrades strong {
  color: var(--gold);
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr));
  gap: 10px;
}

.upgrade-card {
  min-height: 126px;
  display: grid;
  gap: 8px;
  align-content: space-between;
  padding: 12px;
  color: var(--paper);
  text-align: left;
}

.upgrade-card small {
  color: rgba(255, 247, 223, 0.78);
  line-height: 1.3;
}

.upgrade-card.maxed {
  background: rgba(33, 55, 42, 0.72);
}

.upgrade-card.locked {
  background: rgba(22, 13, 11, 0.76);
}

.upgrade-card:disabled {
  opacity: 0.62;
}


.cosmetic-store {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
}

.cosmetic-card {
  min-height: 154px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
  color: var(--paper);
  text-align: left;
}

.cosmetic-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(246, 179, 77, 0.28);
}

.cosmetic-card.locked {
  background: rgba(22, 13, 11, 0.7);
}

.cosmetic-card strong {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.cosmetic-card small,
.cosmetic-card span {
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.76rem;
  line-height: 1.25;
}

.cosmetic-card span {
  color: var(--paper);
  font-weight: 900;
}

.cosmetic-swatch {
  display: block;
  width: 100%;
  height: 36px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 6px;
}
.menu-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.menu-start,
.install-button {
  min-width: 236px;
  min-height: 66px;
  background: linear-gradient(180deg, #a3201d, #66110f);
  color: var(--paper);
  border-bottom: 7px solid #2a0908;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.28rem;
  text-transform: uppercase;
}

.install-button {
  min-width: 178px;
  background: rgba(72, 40, 22, 0.9);
  border: 2px solid rgba(246, 179, 77, 0.55);
  border-bottom: 7px solid #2a0908;
}

.menu-start::after {
  content: " Game";
}

.menu-figure {
  height: min(50vw, 470px);
  align-self: end;
}

.menu-horse,
.menu-rider,
.menu-lasso {
  position: absolute;
  background: #030303;
}

.menu-horse {
  right: 3%;
  bottom: 15%;
  width: min(36vw, 470px);
  aspect-ratio: 2.25;
  border-radius: 50% 44% 42% 48%;
  transform: rotate(-3deg);
}

.menu-horse::before {
  content: "";
  position: absolute;
  right: -15%;
  top: -20%;
  width: 32%;
  height: 54%;
  background: #030303;
  border-radius: 55% 42% 35% 50%;
  transform: rotate(-14deg);
}

.menu-horse::after {
  content: "";
  position: absolute;
  left: -24%;
  top: 20%;
  width: 34%;
  height: 28%;
  background: #030303;
  border-radius: 100% 10% 80% 25%;
  transform: rotate(-18deg);
}

.menu-rider {
  right: 38%;
  bottom: 47%;
  width: min(7.8vw, 96px);
  height: min(15vw, 178px);
  border-radius: 46% 46% 18% 18%;
  transform: rotate(-13deg);
}

.menu-rider::before {
  content: "";
  position: absolute;
  left: 18%;
  top: -31%;
  width: 58%;
  aspect-ratio: 1;
  background: #030303;
  border-radius: 50%;
  box-shadow: 0 -20px 0 -8px #030303, 0 -29px 0 -13px #030303;
}

.menu-rider::after {
  content: "";
  position: absolute;
  left: -28%;
  top: -20%;
  width: 120%;
  height: 12%;
  background: #030303;
  border-radius: 100%;
}

.menu-lasso {
  right: 34%;
  bottom: 71%;
  width: min(13vw, 170px);
  aspect-ratio: 2.1;
  border: 4px solid #030303;
  border-radius: 50%;
  background: transparent;
  transform: rotate(-18deg);
}

.menu-lasso::after {
  content: "";
  position: absolute;
  right: 12%;
  bottom: -86%;
  width: 52%;
  height: 4px;
  background: #030303;
  transform: rotate(36deg);
  transform-origin: right center;
}

.pre-start-screen,
.result-screen {
  position: fixed;
  inset: 0;
  z-index: 19;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 7, 6, 0.45);
  backdrop-filter: blur(4px);
}

.pre-start-screen[hidden],
.result-screen[hidden] {
  display: none;
}

.pre-start-box,
.result-box {
  width: min(620px, 100%);
  display: grid;
  gap: 14px;
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid rgba(255, 247, 223, 0.28);
  border-radius: 8px;
  background: rgba(24, 15, 12, 0.94);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.56);
  text-align: center;
}

.pre-start-box {
  width: min(760px, 100%);
  text-align: left;
}

.pre-start-box > span,
.result-box span {
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-box h2 {
  font-size: clamp(2rem, 5vw, 4rem);
  font-family: Georgia, "Times New Roman", serif;
}

.pre-start-box h2 {
  margin: 0;
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 3.3rem);
}

.result-box p {
  margin: 0;
  color: rgba(255, 247, 223, 0.82);
}

.pre-start-details,
.pre-start-upgrades {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pre-start-details div,
.pre-start-upgrades div {
  min-height: 72px;
  display: grid;
  gap: 5px;
  padding: 12px;
}

.pre-start-upgrades {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}


.result-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  text-align: left;
}

.result-stats div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(255, 247, 223, 0.18);
  border-radius: 8px;
  background: rgba(24, 15, 12, 0.62);
}

.result-stats span {
  color: rgba(255, 247, 223, 0.7);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-stats strong {
  color: var(--gold);
}

.result-stats small {
  color: rgba(255, 247, 223, 0.72);
  font-size: 0.72rem;
}
.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.screen-menu .game-shell {
  opacity: 0;
  pointer-events: none;
}

.screen-playing .main-menu,
.screen-ended .main-menu {
  display: none;
}

.screen-playing .game-shell,
.screen-ended .game-shell {
  opacity: 1;
  pointer-events: auto;
}

.screen-playing .topbar,
.screen-ended .topbar {
  display: none;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(360px, 1fr) auto;
  gap: 14px;
  padding: 18px;
}

.topbar,
.challenge-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
}

.eyebrow,
.challenge-head span,
.hud span {
  margin: 0;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 4px 0 0;
  line-height: 1.04;
}

h1 {
  max-width: 650px;
  font-size: clamp(1.7rem, 3.5vw, 3.9rem);
}

h2 {
  font-size: clamp(1.1rem, 2vw, 1.8rem);
}

.control-grid,
.answer-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.86rem;
  font-weight: 700;
}

select,
input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 247, 223, 0.1);
  color: var(--paper);
  outline: none;
}

select {
  padding: 0 36px 0 12px;
}

option {
  color: #1d1612;
}

input {
  flex: 1 1 260px;
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--aqua);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.18);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--gold);
  color: #23120a;
  font-weight: 900;
  cursor: pointer;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

#micButton {
  background: var(--aqua);
}

#skipButton {
  background: var(--rose);
  color: #fff7df;
}

.arena {
  position: relative;
  overflow: hidden;
  min-height: 360px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 236, 169, 0.88), rgba(235, 148, 37, 0.22) 10%, transparent 22%),
    linear-gradient(180deg, #26130f 0%, #631a13 24%, #b83f1f 52%, #eca715 74%, #170f0e 100%);
  border: 1px solid rgba(255, 247, 223, 0.16);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.finish-line {
  display: none;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: repeat(6, minmax(80px, 1fr));
  gap: 8px;
  pointer-events: none;
}

.arena-prompt {
  position: absolute;
  left: 50%;
  top: 24%;
  width: min(680px, calc(100% - 28px));
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 247, 223, 0.28);
  border-radius: 8px;
  background: rgba(18, 12, 10, 0.82);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  text-align: center;
  pointer-events: none;
}

.arena-prompt span {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.arena-prompt strong {
  color: var(--paper);
  font-size: clamp(1.05rem, 2.6vw, 2rem);
  line-height: 1.08;
}

.hud div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(20, 14, 12, 0.58);
  border: 1px solid rgba(255, 247, 223, 0.14);
}

.hud strong {
  font-size: 1.45rem;
}

.obstacle-status {
  position: absolute;
  top: 88px;
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 9px 16px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: rgba(24, 15, 12, 0.86);
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

.obstacle-status.good { border-color: var(--sage); color: var(--sage); }
.obstacle-status.bad { border-color: var(--rose); color: #ffd0c2; }
.obstacle-status[hidden] { display: none; }

.jump-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 4;
  min-width: 132px;
  background: var(--gold);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.36);
}

.jump-button kbd {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 5px;
  border: 1px solid rgba(35, 18, 10, 0.45);
  border-radius: 4px;
  font-size: 0.7rem;
}

.jump-button.jumping { background: var(--aqua); transform: translateY(-3px); }

.challenge-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    background 180ms ease;
}

.challenge-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.challenge-head p {
  max-width: 520px;
  margin: 0;
  color: rgba(255, 247, 223, 0.8);
}

.challenge-timer {
  min-width: 132px;
  display: grid;
  gap: 3px;
  padding: 9px 12px;
  border: 1px solid rgba(246, 179, 77, 0.32);
  border-radius: 6px;
  background: rgba(246, 179, 77, 0.11);
}

.challenge-timer[hidden] {
  display: none;
}

.challenge-timer span {
  color: var(--gold);
  font-size: 0.66rem;
  font-weight: 900;
  text-transform: uppercase;
}

.challenge-timer strong {
  font-size: 1.35rem;
}

.good {
  color: var(--sage);
}

.bad {
  color: var(--rose);
}

body.question-active {
  overflow: hidden;
}

body.question-active::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(12, 7, 6, 0.42);
  backdrop-filter: blur(3px);
}

body.question-active .challenge-panel {
  position: fixed;
  z-index: 11;
  left: 50%;
  top: 50%;
  width: min(720px, calc(100vw - 28px));
  transform: translate(-50%, -50%);
  background: rgba(24, 15, 12, 0.94);
  border-color: rgba(255, 247, 223, 0.28);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.56);
}

body.question-active .challenge-panel::before {
  content: "Challenge";
  width: max-content;
  padding: 5px 9px;
  border: 1px solid rgba(246, 179, 77, 0.45);
  border-radius: 4px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

body.question-active .challenge-head {
  align-items: start;
  flex-direction: column;
}

body.question-active .challenge-head p {
  max-width: none;
}

@media (max-width: 760px) {
  .main-menu {
    grid-template-columns: 1fr;
    align-content: start;
    overflow: auto;
  }

  .menu-copy h1 {
    font-size: clamp(2.9rem, 15vw, 4.7rem);
  }

  .menu-figure {
    min-height: 250px;
    height: 34vh;
  }

  .difficulty-card,
  .mode-card,
  .menu-start {
    flex: 1 1 100%;
  }

  .menu-stats,
  .horse-store,
  .upgrade-summary,
  .upgrade-grid,
  .pre-start-details,
  .pre-start-upgrades {
    grid-template-columns: 1fr;
  }

  .level-options {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }

  .game-shell {
    padding: 10px;
    grid-template-rows: 52vh auto;
  }

  .topbar,
  .challenge-head {
    align-items: stretch;
    flex-direction: column;
  }

  .control-grid,
  .answer-row {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .arena-prompt {
    top: 36%;
  }

  .finish-line {
    right: 7%;
  }

  body.question-active .challenge-panel {
    max-height: calc(100vh - 24px);
    overflow: auto;
  }
}

@media (max-height: 820px) and (min-width: 761px) {
  .main-menu {
    padding: 18px 48px;
  }

  .menu-kicker,
  .menu-group > span {
    margin-bottom: 7px;
    font-size: 0.66rem;
  }

  .menu-copy h1 {
    font-size: clamp(3rem, 5.6vw, 5.5rem);
  }

  .menu-lede {
    margin: 16px 0;
    font-size: 1rem;
  }

  .menu-group {
    margin-top: 9px;
  }

  .difficulty-card,
  .mode-card {
    min-height: 56px;
  }

  
.cosmetic-store {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
}

.cosmetic-card {
  min-height: 154px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
  color: var(--paper);
  text-align: left;
}

.cosmetic-card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(246, 179, 77, 0.28);
}

.cosmetic-card.locked {
  background: rgba(22, 13, 11, 0.7);
}

.cosmetic-card strong {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.cosmetic-card small,
.cosmetic-card span {
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.76rem;
  line-height: 1.25;
}

.cosmetic-card span {
  color: var(--paper);
  font-weight: 900;
}

.cosmetic-swatch {
  display: block;
  width: 100%;
  height: 36px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 6px;
}
.menu-actions {
    margin-top: 12px;
  }

  .menu-start,
  .install-button {
    min-height: 58px;
  }

  .menu-figure {
    height: min(42vw, 380px);
  }
}

/* ==========================================================
   v9 — menu transitions, tab completion, galloping menu rider
   ========================================================== */

/* Pre-start and result overlays must sit above the fixed main menu */
.pre-start-screen,
.result-screen {
  z-index: 40;
}

/* --- Menu tab polish + completion marker --- */
.menu-tab {
  position: relative;
  overflow: hidden;
  transition:
    background-color 0.22s ease,
    border-color 0.22s ease,
    transform 0.18s ease,
    box-shadow 0.22s ease;
}

.menu-tab:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.menu-tab::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 5px;
  height: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.28s ease;
}

.menu-tab.selected {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.menu-tab.selected::after {
  transform: scaleX(1);
}

.menu-tab.visited::before {
  content: "\2713";
  margin-right: 6px;
  color: var(--gold);
  font-weight: 700;
}

.menu-tab.visited {
  border-color: rgba(238, 179, 30, 0.6);
}

/* --- Menu page transition --- */
@keyframes menuPageIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.menu-page.selected {
  animation: menuPageIn 0.34s ease-out both;
}

.menu-page.selected .menu-group,
.menu-page.selected .horse-store,
.menu-page.selected .upgrade-grid,
.menu-page.selected .cosmetic-store {
  animation: menuPageIn 0.42s ease-out both;
  animation-delay: 0.06s;
}

.horse-card,
.mode-card,
.difficulty-card,
.level-card,
.cosmetic-card,
.upgrade-card,
.menu-start,
.install-button {
  transition:
    transform 0.16s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.horse-card:hover,
.mode-card:hover,
.difficulty-card:hover,
.level-card:hover,
.cosmetic-card:hover,
.upgrade-card:hover,
.menu-start:hover,
.install-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34);
}

.horse-card:active,
.mode-card:active,
.difficulty-card:active,
.level-card:active,
.cosmetic-card:active,
.upgrade-card:active,
.menu-start:active {
  transform: translateY(0) scale(0.98);
}

/* --- Frame-based gallop for the menu silhouette --- */
@keyframes gallopBody {
  0% { transform: rotate(-3deg) translateY(0); }
  25% { transform: rotate(-5deg) translateY(-10px); }
  50% { transform: rotate(-3deg) translateY(-2px); }
  75% { transform: rotate(-1deg) translateY(-8px); }
  100% { transform: rotate(-3deg) translateY(0); }
}

@keyframes gallopRider {
  0% { transform: rotate(-13deg) translateY(0); }
  25% { transform: rotate(-16deg) translateY(-11px); }
  50% { transform: rotate(-13deg) translateY(-3px); }
  75% { transform: rotate(-11deg) translateY(-9px); }
  100% { transform: rotate(-13deg) translateY(0); }
}

@keyframes lassoSpin {
  0% { transform: rotate(-18deg) scaleX(1); }
  50% { transform: rotate(-6deg) scaleX(0.72); }
  100% { transform: rotate(-18deg) scaleX(1); }
}

@keyframes legSwing {
  0% { transform: rotate(28deg); }
  25% { transform: rotate(-24deg); }
  50% { transform: rotate(6deg); }
  75% { transform: rotate(38deg); }
  100% { transform: rotate(28deg); }
}

@keyframes dustPuff {
  0% { opacity: 0.45; transform: translateX(0) scale(0.7); }
  60% { opacity: 0.18; transform: translateX(-38px) scale(1.25); }
  100% { opacity: 0; transform: translateX(-70px) scale(1.5); }
}

.menu-horse {
  animation: gallopBody 0.62s steps(4, end) infinite;
}

.menu-rider {
  animation: gallopRider 0.62s steps(4, end) infinite;
}

.menu-lasso {
  animation: lassoSpin 1.05s steps(6, end) infinite;
}

.menu-leg {
  position: absolute;
  bottom: -34%;
  width: 8%;
  height: 52%;
  background: #030303;
  border-radius: 40% 40% 30% 30%;
  transform-origin: top center;
  animation: legSwing 0.62s steps(4, end) infinite;
}

.menu-leg.leg-a { left: 16%; animation-delay: 0s; }
.menu-leg.leg-b { left: 27%; animation-delay: -0.31s; }
.menu-leg.leg-c { right: 26%; animation-delay: -0.155s; }
.menu-leg.leg-d { right: 15%; animation-delay: -0.465s; }

.menu-dust {
  position: absolute;
  right: 12%;
  bottom: 10%;
  width: min(9vw, 110px);
  aspect-ratio: 2.4;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  animation: dustPuff 0.9s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .menu-horse,
  .menu-rider,
  .menu-lasso,
  .menu-leg,
  .menu-dust,
  .menu-page.selected,
  .menu-page.selected .menu-group {
    animation: none;
  }
}

.building-grid,
.item-grid,
.care-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.building-card,
.item-card,
.care-card {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
  color: var(--paper);
  text-align: left;
}

.building-card strong,
.item-card strong,
.care-card strong {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
}

.building-card small,
.item-card small,
.care-card small,
.building-card em,
.item-card span,
.care-card span {
  color: rgba(255, 247, 223, 0.78);
  font-size: 0.76rem;
  line-height: 1.25;
}

.building-card em,
.item-card span,
.care-card span,
.building-card .effect,
.item-card .effect,
.care-card .effect {
  color: var(--paper);
  font-weight: 900;
}

.building-card.maxed,
.item-card:disabled,
.care-card:disabled {
  opacity: 0.62;
}

.item-bag {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bag-chip,
.bag-empty {
  margin: 0;
  padding: 9px 11px;
  border: 1px solid rgba(255, 247, 223, 0.18);
  border-radius: 999px;
  background: rgba(24, 15, 12, 0.62);
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 800;
}

.stamina-bar {
  position: relative;
  height: 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 6px;
  background: rgba(22, 13, 11, 0.72);
}

.stamina-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #90be6d, #f6b34d);
}

.stamina-bar em {
  position: relative;
  z-index: 1;
  display: block;
  padding: 6px 9px;
  color: var(--ink);
  font-size: 0.72rem;
  font-style: normal;
  font-weight: 900;
}

@media (max-width: 720px) {
  .building-grid,
  .item-grid,
  .care-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile-first touch and safe-area refinements for Android and iOS. */
@media (max-width: 760px) {
  body {
    min-width: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  button,
  select,
  input {
    min-height: 46px;
  }

  .main-menu {
    position: fixed;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 18px;
    padding: max(18px, env(safe-area-inset-top)) 16px 28px;
  }

  .menu-copy h1 {
    font-size: clamp(2.7rem, 14vw, 4.6rem);
  }

  .menu-lede {
    margin: 14px 0 18px;
    font-size: 1rem;
  }

  .menu-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-tab {
    width: 100%;
    padding: 10px 8px;
    font-size: 0.75rem;
  }

  .menu-page {
    width: 100%;
  }

  .store-head {
    align-items: start;
    flex-direction: column;
  }

  .horse-store,
  .upgrade-grid,
  .building-grid,
  .item-grid,
  .care-grid,
  .cosmetic-store,
  .upgrade-summary {
    grid-template-columns: 1fr;
  }

  .level-options {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }

  .menu-actions {
    display: grid;
    grid-template-columns: 1fr;
    margin-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .menu-start,
  .install-button {
    width: 100%;
    min-width: 0;
    min-height: 58px;
  }

  .menu-figure {
    min-height: 180px;
    height: 30vh;
  }

  .game-shell {
    min-height: 100svh;
    padding: max(10px, env(safe-area-inset-top)) 10px 20px;
    grid-template-rows: auto minmax(260px, 46svh) auto;
  }

  .topbar,
  .challenge-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: clamp(1.35rem, 6vw, 2rem);
  }

  .control-grid,
  .answer-row {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .hud div {
    min-height: 52px;
    padding: 7px;
  }

  .hud strong {
    font-size: 1.1rem;
  }

  body.question-active .challenge-panel {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
    padding: 14px;
    overflow: auto;
  }

  .challenge-panel input,
  .challenge-panel button {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .menu-copy h1 {
    font-size: 2.45rem;
  }

  .menu-stats {
    grid-template-columns: 1fr;
  }
}

/* Desktop presentation: give wide Linux browser windows a calmer, denser layout. */
@media (min-width: 761px) {
  body.shop-window-open { overflow: hidden; }

  .main-menu { align-items: start; }
  .menu-copy { align-self: start; }
  .menu-page[data-menu-page="stable"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .menu-page[data-menu-page="stable"] .shop-launchers,
  .menu-page[data-menu-page="stable"] .store-panel { grid-column: 1 / -1; }
  .menu-page[data-menu-page="stable"] .upgrade-panel,
  .menu-page[data-menu-page="stable"] .care-panel { margin-top: 0; }
  .menu-page[data-menu-page="stable"] .upgrade-grid,
  .menu-page[data-menu-page="stable"] .care-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .main-menu {
    grid-template-columns: minmax(560px, 0.92fr) minmax(420px, 1.08fr);
    gap: clamp(34px, 5vw, 96px);
    padding: clamp(32px, 4vw, 64px) clamp(40px, 6vw, 112px);
  }

  .menu-copy { width: min(100%, 820px); }
  .menu-copy h1 { font-size: clamp(4rem, 6.2vw, 7.2rem); }
  .menu-lede { max-width: 650px; }
  .menu-figure { height: min(58vw, 560px); min-height: 390px; }
  .menu-tabs { max-width: 820px; }
  .menu-page { max-width: 980px; }
  .horse-store { grid-template-columns: repeat(3, minmax(190px, 1fr)); }
  .upgrade-grid, .building-grid, .item-grid, .care-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .cosmetic-store { grid-template-columns: repeat(4, minmax(155px, 1fr)); }
  .game-shell { min-height: 100dvh; padding: 24px clamp(24px, 4vw, 72px) 28px; gap: 18px; }
  .arena { min-height: min(680px, calc(100dvh - 210px)); }
  .challenge-panel { width: min(100%, 1280px); margin: 0 auto; padding: 20px 24px; }
  .challenge-head { align-items: center; }
  .answer-row { max-width: 1120px; }
  .answer-row input { min-width: 360px; }
  button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--aqua); outline-offset: 3px; }
}

.shop-launchers { align-content: start; }

.window-launcher {
  width: 100%;
  min-height: 48px;
  background: rgba(34, 19, 14, 0.82);
  border: 1px solid var(--gold);
  color: var(--paper);
}

.shop-window {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 6, 7, 0.72);
  backdrop-filter: blur(10px);
}

.shop-window[hidden] { display: none; }

.shop-window-box {
  width: min(1040px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  padding: clamp(20px, 3vw, 34px);
  border: 1px solid rgba(255, 247, 223, 0.3);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(45, 25, 19, 0.98), rgba(22, 14, 13, 0.98));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}

.shop-window-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.shop-window-head span {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.shop-window-head h2 { margin: 5px 0 0; font-family: Georgia, "Times New Roman", serif; }
.window-close { background: var(--rose); color: var(--paper); }

.stable-details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

@media (max-width: 760px) {
  .stable-details-grid { grid-template-columns: 1fr; }
  .shop-window { padding: 12px; }
  .shop-window-box { max-height: calc(100vh - 24px); }
}

.howto-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 760px;
}

.howto-card {
  display: grid;
  gap: 7px;
  min-height: 116px;
  padding: 14px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
}

.howto-card strong { color: var(--gold); font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; }
.howto-card span { color: rgba(255, 247, 223, 0.82); font-size: 0.82rem; line-height: 1.35; }

.language-picker {
  max-width: 360px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 247, 223, 0.2);
  border-radius: 8px;
  background: rgba(34, 19, 14, 0.72);
}

.language-picker select { width: 100%; }
.language-picker small { color: rgba(255, 247, 223, 0.64); line-height: 1.3; }

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

.confetti-layer.active { opacity: 1; }

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 17px;
  border-radius: 2px;
  transform: rotate(var(--confetti-rotate));
  animation: confettiFall var(--confetti-duration) var(--confetti-delay) ease-out forwards;
}

@keyframes confettiFall {
  0% { transform: translate3d(0, -20px, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(28px, 105vh, 0) rotate(720deg); opacity: 0; }
}

@media (max-width: 760px) {
  .howto-grid { grid-template-columns: 1fr; }
}
