:root {
  --ink: #1d1a17;
  --paper: #fffaf0;
  --gold: #ffd23f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #cfe8f5;
}

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { touch-action: manipulation; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hidden { display: none !important; }

kbd {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 900;
  display: inline-block;
  min-width: 30px;
  padding: 3px 7px;
  margin: 2px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-bottom-width: 4px;
  border-radius: 7px;
  text-align: center;
  line-height: 1.1;
}

.stroke {
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
}

/* ---------- split screen chrome ---------- */

#divider {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 6px;
  margin-left: -3px;
  background: var(--ink);
  z-index: 4;
}

#minimap {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(29, 26, 23, 0.55);
  border: 3px solid var(--ink);
  border-radius: 14px;
  z-index: 5;
}

#mute {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
}

/* ---------- per-player HUD ---------- */

.hud {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 50%;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}
#hud0 { left: 0; }
#hud1 { left: 50%; }
.solo #hud0 { width: 100%; }
.solo #hud0 .hud-top { right: calc(22px + env(safe-area-inset-right)); }
.solo #hud1, .solo #divider { display: none !important; }

/* Show jumping: no place to show, a penalty line under the clock instead */
.faults { display: none; font-size: 18px; color: #fff; }
.faults.bad { color: #ffb4a8; }
.jumping .faults { display: block; }
.jumping .place { display: none; }
.finished .f2.t { font-size: 56px; }

#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 8px 18px;
  font-weight: 900;
  font-size: 15px;
  color: #fff;
  background: var(--ink);
  border: 2px solid #fff;
  border-radius: 999px;
}

.hud-top {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(22px + env(safe-area-inset-left));
  right: 138px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.hud.right .hud-top { left: 138px; right: 22px; flex-direction: row-reverse; }
.hud.right .placebox { text-align: right; }

.place {
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 84px;
  line-height: 0.9;
  color: #fff;
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke fill;
}
.place .suf { font-size: 36px; margin-left: 2px; vertical-align: top; }
.place[data-p="1"] { color: var(--gold); }

.who {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--c);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.stats {
  text-align: right;
  font-family: 'Lilita One', system-ui, sans-serif;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
}
.hud.right .stats { text-align: left; }
.lap { font-size: 34px; }
.lap i { font-style: normal; opacity: 0.85; }
.time { font-size: 24px; color: #fff3c4; }

.hud-bottom { position: absolute; bottom: 18px; left: 22px; }
.hud.right .hud-bottom { left: auto; right: 22px; text-align: right; }

.items { display: flex; gap: 8px; }

.slot {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  font-size: 36px;
  background: rgba(29, 26, 23, 0.45);
  border: 3px solid var(--ink);
  border-radius: 16px;
  transition: background 0.15s;
}
.slot .ico { display: inline-block; }
.slot.full { background: var(--c); }
.slot.next { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink); }
.hud.right .items { flex-direction: row-reverse; }

.items.bump .slot.full .ico { animation: bump 0.35s ease-out; }
@keyframes bump { 40% { transform: scale(1.45) rotate(-12deg); } }

.hint {
  margin-top: 8px;
  font-weight: 800;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}
.hint kbd { font-size: 11px; min-width: 0; padding: 1px 5px; border-bottom-width: 3px; }

.cd {
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 170px;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 12px var(--ink);
  paint-order: stroke fill;
  opacity: 0;
}
.cd.pop { animation: pop 0.95s ease-out forwards; }
.cd.go { color: #7dd956; }
@keyframes pop {
  0% { transform: scale(1.8); opacity: 0; }
  15% { transform: scale(1); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: scale(0.9); opacity: 0; }
}

.msg {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: clamp(28px, 3.6vw, 54px);
  -webkit-text-stroke: 8px var(--ink);
  paint-order: stroke fill;
  opacity: 0;
  padding: 0 12px;
}
.msg.show { animation: msg 1.6s ease-out forwards; }
.msg.bad { color: #ff6b6b; }
.msg.good { color: #7dd956; }
.msg.gold { color: var(--gold); }
@keyframes msg {
  0% { transform: translateY(20px) scale(0.6); opacity: 0; }
  12% { transform: none; opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(-14px); opacity: 0; }
}

.alert {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  white-space: nowrap;
  padding: 6px 18px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 30px;
}
.alert.show { display: block; animation: blink 0.5s steps(2) infinite; }
.wrong { top: 44%; background: var(--gold); color: var(--ink); }
.incoming { bottom: 120px; background: #ff5c8a; }
@keyframes blink { 50% { opacity: 0.4; } }

.finished {
  position: absolute;
  top: 26%;
  left: 0;
  right: 0;
  display: none;
  text-align: center;
  font-family: 'Lilita One', system-ui, sans-serif;
  line-height: 1;
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke fill;
}
.finished.show { display: block; animation: popin 0.6s cubic-bezier(0.2, 1.6, 0.4, 1); }
.finished .f1 { font-size: 92px; color: var(--gold); }
.finished .f2 { font-size: 64px; margin-top: 6px; }
.finished .f2 sup { font-size: 30px; }
@keyframes popin { from { transform: scale(0.3); opacity: 0; } }

.flash {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 140px 40px rgba(255, 40, 90, 0.75);
  opacity: 0;
}
.flash.on { animation: flash 0.8s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at center, rgba(20, 16, 12, 0.25), rgba(20, 16, 12, 0.7));
}

.card {
  width: 100%;
  max-width: 920px;
  margin: auto;
  padding: 26px 34px 22px;
  text-align: center;
  color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 10px 0 var(--ink);
}
.card.small { max-width: 560px; }

.title {
  font-family: 'Lilita One', system-ui, sans-serif;
  font-weight: 400;
  font-size: 92px;
  line-height: 1;
  color: #ff8a1f;
  -webkit-text-stroke: 9px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink);
}
.title.mid { font-size: 64px; -webkit-text-stroke-width: 7px; }

.tag { margin: 12px 0 20px; font-weight: 800; font-size: 18px; color: #6b5a48; }

.players { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pcard {
  padding: 14px 12px 12px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--c);
}
.pcard h3 {
  font-family: 'Lilita One', system-ui, sans-serif;
  font-weight: 400;
  font-size: 30px;
  color: var(--c);
}
.pcard h3 span { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; color: #8a7a68; }
.keys { display: flex; justify-content: center; align-items: center; gap: 22px; margin-top: 8px; min-height: 86px; }
.cluster { display: flex; flex-direction: column; align-items: center; }
.cluster kbd { width: 40px; font-size: 18px; }
.acts { display: flex; gap: 10px; }
.acts > div { display: flex; flex-direction: column; align-items: center; }
.acts kbd.wide { min-width: 84px; font-size: 14px; padding: 8px 8px; background: var(--c); color: #fff; }
.acts small { font-weight: 800; color: #8a7a68; margin-top: 4px; }
.pcard.ai { opacity: 0.75; box-shadow: 0 6px 0 #b9b0a4; }
.aitext { font-weight: 800; color: #6b5a48; max-width: 260px; }

.settings { display: grid; gap: 8px; margin-bottom: 18px; text-align: left; }
.row {
  display: grid;
  grid-template-columns: 90px 1fr;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border: 3px solid transparent;
  border-radius: 16px;
}
.row.focus { border-color: var(--ink); background: #fff3c4; }
.label { font-family: 'Lilita One', system-ui, sans-serif; font-size: 22px; }
.opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip {
  font: 800 16px 'Nunito', system-ui, sans-serif;
  cursor: pointer;
  padding: 6px 14px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
}
.chip.on { background: #43a047; color: #fff; }
.tracks { display: flex; gap: 10px; flex-wrap: wrap; }
.tcard {
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 150px;
  padding: 6px 8px 8px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
}
.tcard canvas { width: 120px; height: 60px; }
.tcard b { font-family: 'Lilita One', system-ui, sans-serif; font-weight: 400; font-size: 17px; }
.tcard small { font-weight: 800; font-size: 12px; color: #8a7a68; }
.tcard.on { background: #43a047; color: #fff; box-shadow: 0 4px 0 var(--ink); }
.tcard.on small { color: #e7f5e0; }
.blurb { flex-basis: 100%; font-weight: 700; font-size: 14px; color: #6b5a48; }

.howto { margin: 18px auto 10px; max-width: 760px; font-weight: 700; font-size: 15px; line-height: 1.45; color: #4a3f35; }
.howto span { display: inline-block; margin: 0 10px; }

.laps { font-family: 'Lilita One', system-ui, sans-serif; font-size: 26px; }
.laps b { display: inline-block; min-width: 46px; font-weight: 400; }
.arrow {
  font: inherit;
  width: 40px;
  height: 40px;
  line-height: 30px;
  cursor: pointer;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
}

.start {
  display: inline-block;
  cursor: pointer;
  padding: 10px 26px;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 28px;
  color: #fff;
  background: #43a047;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  animation: pulse 1.3s ease-in-out infinite;
}
.start.still { animation: none; }
@keyframes pulse { 50% { transform: scale(1.05); } }

.btnrow { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 14px; }

.foot { margin-top: 14px; font-weight: 800; font-size: 13px; color: #8a7a68; }

.winner { margin: 14px 0 12px; font-weight: 900; font-size: 22px; }
.duel { margin: 12px 0 16px; font-weight: 800; color: #6b5a48; }

#resultTable { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-weight: 800; font-size: 20px; }
#resultTable td { padding: 8px 12px; background: #fff; border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }
#resultTable td:first-child { border-left: 3px solid var(--ink); border-radius: 12px 0 0 12px; width: 60px; font-size: 26px; }
#resultTable td:last-child { border-right: 3px solid var(--ink); border-radius: 0 12px 12px 0; text-align: right; font-variant-numeric: tabular-nums; }
#resultTable tr.human td { background: #fff3c4; }
#resultTable td.name { text-align: left; }
.dot { display: inline-block; width: 16px; height: 16px; margin-right: 10px; border: 2px solid var(--ink); border-radius: 50%; vertical-align: -1px; }

@media (max-height: 900px) {
  #menu .title { font-size: 64px; -webkit-text-stroke-width: 7px; text-shadow: 0 5px 0 var(--ink); }
  #menu .tag { margin: 6px 0 12px; }
  .card { padding: 18px 26px 16px; }
  .settings { gap: 4px; margin-bottom: 12px; }
  .howto { margin-top: 12px; font-size: 14px; }
}

/* ---------- horse picker ---------- */

.horses { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; }
.hcard {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 3px 5px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: inset 0 -5px 0 var(--c);
  min-width: 0;
}
.hcard img { width: 100%; max-width: 88px; aspect-ratio: 4 / 3; object-fit: contain; }
.hcard b { font-family: 'Lilita One', system-ui, sans-serif; font-weight: 400; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hcard.on { background: #fff3c4; border-color: #e53935; box-shadow: inset 0 -5px 0 var(--c), 0 0 0 3px #e53935; }
.hcard.p2 { border-color: #1e88e5; box-shadow: inset 0 -5px 0 var(--c), 0 0 0 3px #1e88e5; }
.badge {
  position: absolute;
  top: -8px;
  right: -6px;
  font: 900 11px 'Nunito', system-ui, sans-serif;
  font-style: normal;
  color: #fff;
  background: #e53935;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0 6px;
}
.badge:empty { display: none; }
.hcard.p2 .badge { background: #1e88e5; }
.hdetail { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; width: 100%; }
.hname { display: inline-flex; align-items: center; gap: 4px; }
.hname input {
  width: 150px;
  font: 400 18px 'Lilita One', system-ui, sans-serif;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 3px 8px;
  -webkit-user-select: text;
  user-select: text;
}
.hstats { display: flex; flex-wrap: wrap; gap: 2px 12px; font-weight: 800; font-size: 12px; color: #6b5a48; }
.st b { color: #ff8a1f; letter-spacing: 1px; font-weight: 400; }
.st i { color: #d9d0c3; font-style: normal; letter-spacing: 1px; }
.h2pick { width: 66px; border: 3px solid #1e88e5; border-radius: 12px; background: #fff; box-shadow: inset 0 -5px 0 var(--c); }
.h2pick img { width: 100%; display: block; aspect-ratio: 4 / 3; }

#menuBtn {
  position: fixed;
  top: calc(142px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  cursor: pointer;
  font: 900 13px 'Nunito', system-ui, sans-serif;
  color: #fff;
  background: rgba(29, 26, 23, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 4px 12px;
}

/* ---------- touch controls ---------- */

#touch { position: fixed; inset: 0; z-index: 7; pointer-events: none; }
#steerZone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 72%;
  pointer-events: auto;
  touch-action: none;
}
.steer-hint {
  position: absolute;
  left: calc(24px + env(safe-area-inset-left));
  bottom: calc(26px + env(safe-area-inset-bottom));
  padding: 8px 16px;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 18px;
  color: #fff;
  background: rgba(29, 26, 23, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  white-space: nowrap;
  transition: opacity 0.2s;
}
#steerZone.active .steer-hint { opacity: 0; }
.stick {
  position: absolute;
  display: none;
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(29, 26, 23, 0.25);
}
.stick.on { display: block; }
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  margin: -31px 0 0 -31px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--ink);
}
.tbtns {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: "item ." "brake jump";
  align-items: end;
  gap: 12px 14px;
  pointer-events: auto;
}
.tbtn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 78px;
  height: 78px;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.9);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 5px 0 var(--ink);
  touch-action: none;
  -webkit-user-select: none;
}
.tbtn small { font-family: 'Nunito', system-ui, sans-serif; font-weight: 900; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-top: 3px; }
.tbtn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.tbtn.big { width: 104px; height: 104px; font-size: 40px; background: #43a047; color: #fff; }
#tJump { grid-area: jump; }
#tBrake { grid-area: brake; }
#tItem { grid-area: item; background: #e53935; color: #fff; font-size: 34px; }
#tItem.empty { background: rgba(29, 26, 23, 0.45); }
#tItem.empty .ico { opacity: 0.4; }
#tItem .queue { position: absolute; top: -8px; right: -10px; font-size: 18px; letter-spacing: -2px; }
.tbtn.small {
  position: absolute;
  top: calc(96px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  width: 46px;
  height: 46px;
  font-size: 14px;
  pointer-events: auto;
}

/* ---------- touch mode: hide keyboard-only bits ---------- */

.touchhelp, .rotate { display: none; }
.touch .touchhelp { display: grid; gap: 8px; margin: 4px 0 12px; font-weight: 700; font-size: 15px; color: #4a3f35; text-align: left; }
.touch .touchhelp div { padding: 8px 12px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; }
.touch .foot, .touch .hud-bottom, .touch .pkeys { display: none; }
.touch #modeOpts .kbonly { opacity: 0.4; pointer-events: none; }
.touch .row.focus { border-color: transparent; background: none; }
.touch .incoming { bottom: auto; top: 60%; }
@media (orientation: portrait) {
  .touch .rotate { display: block; margin: 6px 0 4px; font-weight: 900; font-size: 14px; color: #ff8a1f; }
}

/* ---------- small screens (phones) ---------- */

@media (max-width: 760px), (max-height: 560px) {
  .place { font-size: 54px; -webkit-text-stroke-width: 6px; }
  .place .suf { font-size: 24px; }
  .who { font-size: 10px; padding: 1px 8px; letter-spacing: 1px; margin-top: 4px; }
  .stats { -webkit-text-stroke-width: 5px; }
  .lap { font-size: 24px; }
  .time { font-size: 16px; }
  .hud-top { top: calc(8px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); }
  .solo #hud0 .hud-top { right: calc(12px + env(safe-area-inset-right)); }
  #minimap { top: calc(8px + env(safe-area-inset-top)); border-width: 2px; border-radius: 10px; }
  .cd { font-size: 110px; -webkit-text-stroke-width: 9px; }
  .msg { font-size: 30px; -webkit-text-stroke-width: 6px; }
  .alert { font-size: 18px; padding: 4px 12px; }
  .finished .f1 { font-size: 58px; }
  .finished .f2 { font-size: 42px; }
  .tbtn.small { top: calc(74px + env(safe-area-inset-top)); }
  #menuBtn { top: calc(96px + env(safe-area-inset-top)); font-size: 11px; padding: 3px 10px; }
  .hcard b { font-size: 11px; }
  .hname input { width: 120px; font-size: 15px; }
  .hstats { font-size: 10px; gap: 0 8px; }

  .card { padding: 14px 16px 14px; border-radius: 20px; box-shadow: 0 6px 0 var(--ink); }
  #menu .title, .title { font-size: 44px; -webkit-text-stroke-width: 5px; text-shadow: 0 4px 0 var(--ink); }
  .title.mid { font-size: 40px; }
  #menu .tag { font-size: 13px; margin: 6px 0 10px; }
  .settings { gap: 2px; margin-bottom: 10px; }
  .row { grid-template-columns: 64px 1fr; gap: 8px; padding: 3px 6px; }
  .label { font-size: 16px; }
  .chip { font-size: 13px; padding: 5px 10px; }
  .tracks { gap: 6px; }
  .tcard { width: 98px; padding: 4px 4px 6px; border-radius: 12px; }
  .tcard canvas { width: 84px; height: 42px; }
  .tcard b { font-size: 12px; }
  .tcard small { font-size: 9px; }
  .blurb { font-size: 12px; }
  .laps { font-size: 20px; }
  .arrow { width: 34px; height: 34px; line-height: 24px; }
  .howto { font-size: 12px; margin: 8px auto 8px; }
  .howto span { margin: 0 4px; }
  .touch .touchhelp { font-size: 13px; }
  .start { font-size: 22px; padding: 8px 20px; }
  .winner { font-size: 17px; margin: 8px 0; }
  #resultTable { font-size: 15px; }
  #resultTable td { padding: 5px 8px; }
  #resultTable td:first-child { font-size: 20px; width: 44px; }
}

@media (max-width: 480px) {
  /* Narrow portrait phone: stack the buttons in one column on the right edge. */
  .tbtns { grid-template-columns: auto; grid-template-areas: "brake" "item" "jump"; justify-items: center; gap: 10px; }
  .steer-hint { font-size: 14px; padding: 6px 12px; }
  .row { grid-template-columns: 1fr; gap: 4px; }
  .tcard { width: 88px; }
  .tcard canvas { width: 76px; height: 38px; }
  .horses { gap: 4px; }
  .howto span { display: block; margin: 2px 0; }
}

/* Phone held sideways: settings on the left, help and the start button on the right. */
@media (max-height: 560px) and (orientation: landscape) {
  .cols { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; align-items: center; }
  #menu .title { font-size: 32px; -webkit-text-stroke-width: 4px; text-shadow: 0 3px 0 var(--ink); }
  .horses { grid-template-columns: repeat(8, 1fr); gap: 3px; }
  .hcard { padding: 2px; border-width: 2px; border-radius: 8px; }
  .hcard b { display: none; }
  .tcard { width: 92px; padding: 3px; }
  .tcard canvas { width: 64px; height: 32px; }
  .tcard b { font-size: 11px; white-space: nowrap; }
  .tcard small { display: none; }
  .row { padding-top: 1px; padding-bottom: 1px; }
  .touch .touchhelp { font-size: 12px; gap: 6px; }
  #menu .card { max-width: 860px; }
  #menu .tag, .blurb { display: none; }
  .settings { margin-bottom: 0; }
  .side .howto { display: none; }
  .touch .touchhelp { margin-top: 0; }
  .tbtn { width: 66px; height: 66px; font-size: 22px; }
  .tbtn.big { width: 88px; height: 88px; font-size: 34px; }
  #tItem { font-size: 28px; }
}

/* Wide screens: settings on the left, controls and the start button on the right. */
@media (min-width: 1100px) and (min-height: 680px) {
  #menu .card { max-width: 1200px; }
  .cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 24px; align-items: center; }
  .side .players { grid-template-columns: 1fr; gap: 12px; }
  .side .keys { min-height: 0; }
  .side .howto span { display: block; margin: 3px 0; }
  .settings { gap: 0; }
  #menu .tag { margin: 4px 0 8px; }
  .row { padding: 3px 10px; }
  .tcard canvas { width: 100px; height: 50px; }
  .tcard { width: 136px; padding: 4px 6px 6px; }
}

/* Pure race: no items anywhere */
.noweapons .hud-bottom .items, .noweapons #tItem, .noweapons .howto span:not(:nth-last-child(2)) { display: none; }
.duel { white-space: pre-line; }
.records { margin: 0; padding: 4px 4px 4px 26px; font-weight: 800; font-size: 14px; text-align: left; font-variant-numeric: tabular-nums; }
.records li { margin: 2px 0; }
.records small { color: #8a7a68; }

/* ---------- player columns ---------- */

.row.animals { grid-template-columns: 1fr; }
.row.animals > .label { display: none; }
.pcols { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pcols[data-n="1"] { grid-template-columns: 1fr 0.6fr; }
.pcol {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 8px 8px;
  background: #fff;
  border: 3px solid var(--c, var(--ink));
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--c, #b9b0a4);
  overflow: hidden;
}
.phead {
  align-self: stretch;
  margin: 0 -8px 2px;
  padding: 3px 0 4px;
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 20px;
  text-align: center;
  color: #fff;
  background: var(--c, #8a7a68);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
}
.ppick { display: flex; align-items: center; gap: 4px; }
.ppick img { width: 104px; aspect-ratio: 4 / 3; cursor: pointer; }
.ppick .arrow { width: 32px; height: 32px; line-height: 22px; }
.pspecies { font-weight: 900; font-size: 13px; color: #6b5a48; }
.pcol .hname input { width: 140px; text-align: center; }
.pcol .hstats { justify-content: center; }
.pkeys { font-weight: 800; font-size: 12px; color: #4a3f35; text-align: center; line-height: 1.5; }
.pkeys kbd { font-size: 11px; min-width: 0; padding: 0 5px; border-bottom-width: 3px; margin: 1px; }
.pkeys small { color: #8a7a68; }
.aicol { justify-content: center; border-color: #b9b0a4; box-shadow: 0 5px 0 #d9d0c3; }
.aicol .phead { background: #b9b0a4; }
.aicol .aitext { padding: 8px 4px; }
.row.animals.focus { border-color: var(--ink); }
.pcols[data-n="1"] .aicol { display: flex; }

@media (max-width: 760px), (max-height: 560px) {
  .pcols { gap: 6px; }
  .phead { font-size: 16px; }
  .ppick img { width: 78px; }
  .pcol .hname input { width: 110px; }
  .pkeys { font-size: 10px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .ppick img { width: 64px; }
  .pcol { padding-bottom: 4px; gap: 2px; }
  .pcol .hstats { display: none; }
}

/* compact player cards */
.pcol { gap: 2px; }
.phead { font-size: 18px; padding: 2px 0 3px; }
.ppick img { width: 88px; }
.pcol .hstats { display: grid; grid-template-columns: auto auto; gap: 0 10px; font-size: 11px; }
.pcol .hname input { font-size: 16px; padding: 1px 8px; }
.pkeys { font-size: 11px; line-height: 1.4; }
@media (min-width: 1100px) and (min-height: 680px) {
  .side .howto { margin: 8px 0 6px; }
  .side .howto span { display: inline-block; margin: 0 6px; }
  #menu .card { padding-top: 14px; }
}
.st { white-space: nowrap; }
.pickhint { font-weight: 800; font-size: 12px; color: #8a7a68; text-align: center; margin-top: 2px; }
.touch .pickhint { display: none; }
@media (min-width: 1100px) and (min-height: 680px) {
  .start { white-space: nowrap; font-size: 24px; }
}

/* Show jumping has its own line of help; it comes last so it wins over the layouts above. */
.howto span.jumphow, .jumping .howto span { display: none; }
.jumping .howto span.jumphow { display: inline-block; }
.jumping .aicol { justify-content: flex-start; }
