:root {
  color-scheme: light;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", Arial, sans-serif;
  background: #78d7ef;
  color: #3c2616;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
}

body {
  min-height: 100svh;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button, a { font: inherit; }

button,
a,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

button,
[role="button"] {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.racer-shell {
  --route-sky: #72d6ee;
  --route-ground: #7ecb5f;
  position: relative;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
  background: linear-gradient(var(--route-sky), color-mix(in srgb, var(--route-sky), white 30%) 56%, var(--route-ground) 56%);
  transition: background .35s ease;
}

#racer-game {
  display: block;
  width: min(100vw, calc(100svh * 16 / 9));
  height: auto;
  max-height: 100svh;
  aspect-ratio: 16 / 9;
}

@media (max-width: 720px) and (orientation: portrait) {
  #racer-game {
    width: 100vw;
    height: 100svh;
    max-height: none;
    aspect-ratio: auto;
  }
}

.racer-hud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) auto max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: flex-start;
  gap: 9px;
  pointer-events: none;
}

.home-link, .race-stat {
  border: 3px solid rgba(72, 48, 23, .2);
  border-radius: 12px;
  background: rgba(255, 250, 212, .86);
  box-shadow: 0 3px 0 rgba(86, 56, 28, .18);
}

.home-link {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  color: #5c3820;
  font-size: 1.55rem;
  font-weight: 900;
  pointer-events: auto;
  text-decoration: none;
}

.race-stat {
  min-width: 76px;
  padding: 5px 9px 6px;
  text-align: center;
}

.race-stat span { display: block; color: #99633d; font-size: 9px; font-weight: 900; letter-spacing: .08em; }
.race-stat strong { display: block; color: #49301d; font-size: 18px; line-height: 1.05; }
.race-stat.position { background: rgba(209, 239, 180, .92); }
.race-stat.route { min-width: 114px; background: rgba(205, 221, 245, .92); }
.race-stat.route strong { max-width: 130px; overflow: hidden; font-size: 13px; line-height: 1.42; text-overflow: ellipsis; white-space: nowrap; }
.race-stat.speed { margin-left: auto; min-width: 104px; background: rgba(254, 218, 99, .9); }
.race-stat.timer { background: rgba(238, 127, 82, .9); }
.race-stat.timer span, .race-stat.timer strong { color: #fff9df; }

.screen {
  position: absolute;
  z-index: 3;
  width: min(92vw, 700px);
  max-height: min(90svh, 710px);
  overflow: auto;
  padding: clamp(18px, 3vw, 32px);
  border: 5px solid #704227;
  border-radius: 28px;
  background: #fff4c9;
  box-shadow: 0 12px 0 #d68e45, 0 22px 48px rgba(64, 37, 18, .33);
  text-align: center;
}

.start-screen { width: min(94vw, 820px); max-height: 96svh; transform: rotate(-.8deg); }
.eyebrow { margin: 0 0 4px; color: #bb5836; font-size: clamp(.68rem, 1.7vw, .9rem); font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
h1, h2 { margin: 0; color: #5b321e; font-weight: 900; line-height: .84; text-shadow: 0 3px 0 #f5b84a; }
h1 { font-size: clamp(3rem, 7.5vw, 5.7rem); }
h1 em { color: #e95335; font-style: normal; }
h2 { font-size: clamp(2.5rem, 7vw, 4.8rem); }
.intro { max-width: 480px; margin: 14px auto 16px; font-size: clamp(.98rem, 2.2vw, 1.18rem); font-weight: 800; line-height: 1.25; }

.horse-picker { display: grid; grid-template-columns: repeat(4, minmax(92px, 1fr)); gap: 9px; margin: 12px auto 17px; }
.horse-card {
  min-height: 130px;
  padding: 7px 4px 8px;
  border: 3px solid #d39a54;
  border-radius: 14px;
  background: #fffbed;
  color: #5c3820;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.05;
  transition: transform .15s, background .15s, border-color .15s;
}
.horse-card:hover, .horse-card:focus-visible { transform: translateY(-4px) rotate(-2deg); outline: none; }
.horse-card[aria-pressed="true"] { border-color: #e34d31; background: #ffd966; transform: translateY(-4px) rotate(-2deg); box-shadow: 0 4px 0 #e99e40; }
.horse-card canvas { display: block; width: 100%; height: 80px; margin-bottom: 3px; }

.picker-label { margin: -5px 0 7px; color: #99633d; font-size: .72rem; font-weight: 900; letter-spacing: .12em; }
.route-picker { display: grid; grid-template-columns: repeat(4, minmax(105px, 1fr)); gap: 9px; margin: 0 auto 14px; }
.route-card {
  position: relative;
  min-height: 88px;
  overflow: hidden;
  padding: 0;
  border: 3px solid #a8825b;
  border-radius: 14px;
  background: #e7dbbd;
  color: #fff;
  cursor: pointer;
  text-align: left;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.route-card:hover, .route-card:focus-visible { transform: translateY(-3px) rotate(1deg); outline: none; }
.route-card[aria-pressed="true"] { border-color: #e34d31; transform: translateY(-3px) rotate(1deg); box-shadow: 0 4px 0 #e99e40; }
.route-card canvas { display: block; width: 100%; height: 82px; }
.route-card-copy { position: absolute; inset: auto 0 0; padding: 17px 7px 7px; background: linear-gradient(transparent, rgba(35, 24, 20, .85)); text-shadow: 0 1px 2px #28180f; }
.route-card strong { display: block; }
.route-card strong { font-size: .77rem; font-weight: 900; letter-spacing: .02em; }

@media (max-height: 800px) and (min-width: 531px) {
  .start-screen { padding: 15px 26px 17px; }
  .start-screen h1 { font-size: clamp(3rem, 9svh, 4.2rem); }
  .start-screen .intro { margin: 8px auto 10px; font-size: .94rem; }
  .start-screen .horse-picker { margin-block: 7px 12px; }
  .start-screen .horse-card { min-height: 100px; }
  .start-screen .horse-card canvas { height: 59px; }
  .start-screen .route-card { min-height: 74px; }
  .start-screen .route-card canvas { height: 70px; }
  .start-screen .controls-copy { margin-bottom: 9px; }
  .start-screen .big-button { padding-block: 10px; }
}

.controls-copy { margin: 0 0 15px; color: #805036; font-size: .82rem; font-weight: 700; }
.big-button {
  padding: 13px 22px;
  border: 4px solid #723f23;
  border-radius: 999px;
  background: #eb5838;
  box-shadow: 0 5px 0 #9e3d27;
  color: #fff9df;
  cursor: pointer;
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  font-weight: 900;
  letter-spacing: .03em;
}
.big-button:hover, .big-button:focus-visible { background: #f36e42; transform: translateY(-2px); outline: none; }
.big-button:active { transform: translateY(4px); box-shadow: 0 1px 0 #9e3d27; }
.finish-screen { max-width: 480px; }
.finish-screen p:not(.eyebrow) { font-weight: 800; }
.tiny-link { display: block; margin: 16px 0 0; color: #815139; font-size: .85rem; font-weight: 800; }

.touch-controls {
  position: absolute;
  z-index: 2;
  right: max(15px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: none;
  gap: 7px;
}
.touch-controls button {
  width: 54px;
  height: 48px;
  border: 3px solid rgba(90, 53, 26, .55);
  border-radius: 14px;
  background: rgba(255, 247, 198, .87);
  color: #56341e;
  box-shadow: 0 3px 0 rgba(89, 48, 22, .24);
  font-size: 1.4rem;
  font-weight: 900;
}
.touch-controls button[data-control="jump"] { width: 68px; background: rgba(250, 216, 91, .92); font-size: .78rem; }

@media (pointer: coarse), (max-width: 720px) { .touch-controls { display: flex; } }
@media (max-width: 720px) {
  .touch-controls {
    left: max(15px, env(safe-area-inset-left));
    right: max(15px, env(safe-area-inset-right));
  }
  .touch-controls button,
  .touch-controls button[data-control="jump"] {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 56px;
  }
}
@media (max-width: 530px) {
  .horse-picker { grid-template-columns: repeat(2, 1fr); max-width: 300px; }
  .route-picker { grid-template-columns: repeat(2, 1fr); max-width: 300px; }
  .horse-card { min-height: 100px; }
  .horse-card canvas { height: 58px; }
  .screen { max-height: 84svh; }
  .race-stat { min-width: 63px; padding-inline: 5px; }
  .race-stat strong { font-size: 15px; }
  .race-stat.route { display: none; }
  .race-stat.speed { min-width: 78px; }
}
