:root {
  --crude: #150e0a;
  --crude-2: #241812;
  --sky: #f2a33a;
  --dust: #c98a4a;
  --brass: #e8b84a;
  --brass-deep: #94681a;
  --cream: #f6ecd4;
  --muted: #bda98d;
  --up: #8df0b4;
  --down: #ff9a7c;
  --red: #d2401f;
  --display: 'Rye', 'Rockwell', Georgia, serif;
  --body: 'Archivo', 'Arial Narrow', Arial, sans-serif;
  --strip: 50px;
  --split: 40%; /* the race takes this much of the screen, the trading the rest */
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background: #2c1a10;
  color: var(--cream);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* A phone-shaped stage: full screen on a phone, centred on a desktop. */
#stage {
  position: relative;
  width: min(100vw, 62dvh);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--crude);
  touch-action: none;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.topbar {
  position: absolute; top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 10px; pointer-events: none;
}
.standing { color: var(--crude); font-weight: 700; font-size: 14px; }
.standing b { font-family: var(--display); font-weight: 400; font-size: 27px; line-height: 1; }
.rival { display: block; font-size: 13px; font-weight: 700; }
.topbtns { display: flex; gap: 6px; pointer-events: auto; }
.smallbtn {
  min-height: 34px; padding: 4px 10px; border: 0; border-radius: 6px;
  background: rgba(21, 14, 10, .78); color: var(--cream); font-size: 13px; font-weight: 700;
}

/* The ground between the two halves: a cut through the rock. */
.strip {
  position: absolute; left: 0; right: 0; top: calc(var(--split) - var(--strip) / 2); height: var(--strip);
  display: grid; grid-template-columns: 84px 1fr 84px; align-items: center; gap: 8px; padding: 0 10px;
  background:
    linear-gradient(#8a5a33 0 5px, #5c3820 5px 13px, #3a2214 13px 34px, #241812 34px);
  pointer-events: none;
}
.stat { display: flex; flex-direction: column; line-height: 1.05; }
.stat.right { text-align: right; }
.statlabel { font-size: 11px; font-weight: 700; color: var(--muted); }
.stat b { font-size: 18px; font-weight: 800; font-stretch: 80%; white-space: nowrap; transition: color .2s; }
.stat b.up { color: var(--up); }
.stat b.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 30% { transform: scale(1.28); color: var(--brass); } }
.stat.right b { transform-origin: right center; }
.stat:not(.right) b { transform-origin: left center; }
.mile { display: flex; flex-direction: column; gap: 5px; align-items: center; min-width: 0; }
.milelabel { font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; }
/* The whole mile, one marker per horse. The right edge is the finish. */
.milebar { position: relative; width: 100%; height: 4px; border-radius: 2px; background: #6b4a2c; border-right: 3px solid var(--cream); }
.mark { position: absolute; top: 50%; left: 0; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(246, 236, 212, .55); }
.mark.me { width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; background: var(--brass); box-shadow: 0 0 0 2px var(--crude); z-index: 1; }

.cashline {
  position: absolute; left: 10px; right: 10px; top: calc(var(--split) + var(--strip) / 2 + 4px);
  display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); pointer-events: none;
}
/* Whether you can bet Yes and No yet: each fills back up over its cooldown. */
.ready { display: flex; gap: 4px; }
.pill { position: relative; width: 38px; height: 18px; border-radius: 5px; background: #33261c; overflow: hidden; text-align: center; }
.pill i { position: absolute; inset: 0 auto 0 0; width: 100%; }
.pill.yes i { background: #8df0b4; }
.pill.no i { background: #ff8a6b; }
.pill em { position: relative; font-style: normal; font-size: 12px; font-weight: 800; line-height: 18px; color: #150e0a; }
.pill.cooling em { color: var(--cream); }
/* Long or short: right under the thumb, the full width of the screen. */
.biasbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr 1fr 66px; gap: 6px;
  padding: 6px 8px calc(6px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: #241812; border-top: 2px solid #6b4a2c;
}
/* Oil over the long term, for choosing a side. Green and red stay reserved for Yes and No. */
.longchart { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; height: 24px; font-size: 12px; color: var(--muted); }
.longchart svg { width: 100%; height: 22px; display: block; }
.longlabel { font-weight: 700; white-space: nowrap; }
.longchange { font-weight: 800; color: var(--cream); white-space: nowrap; }
.biasbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 50px; border: 0; border-radius: 8px;
  background: #3a2819; color: var(--muted); touch-action: manipulation;
}
.biasbtn[aria-pressed='true'] { background: var(--brass); color: var(--crude); box-shadow: 0 3px 0 var(--brass-deep); }
.biasbar.cooling .biasbtn[aria-pressed='false'] { opacity: .5; }
.dial {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px; padding: 0;
  border: 0; background: none; color: var(--muted); touch-action: none; cursor: grab;
}
.dialface { position: relative; width: 42px; height: 42px; }
.dialtick { position: absolute; left: 50%; top: 50%; width: 2px; height: 4px; margin: -2px 0 0 -1px; background: #8a6a44; transform: rotate(var(--a)) translateY(-19px); }
.dialknob {
  position: absolute; inset: 5px; display: grid; place-items: center; border-radius: 50%;
  background: var(--brass); box-shadow: 0 2px 0 var(--brass-deep);
}
.dialknob::before {
  content: ''; position: absolute; left: 50%; top: 1px; width: 3px; height: 6px; margin-left: -1.5px; border-radius: 2px;
  background: var(--crude); transform-origin: 50% 15px; transform: rotate(var(--turn, -67.5deg));
}
.dialknob b { font-size: 12px; font-weight: 900; color: var(--crude); line-height: 1; padding-top: 4px; }
.dial.cooling .dialknob { opacity: .6; }
.dialname { font-size: 10px; font-weight: 700; line-height: 1; }
.biasname { display: flex; align-items: center; gap: 7px; font-size: 19px; font-weight: 900; line-height: 1.1; }
.biasfx { font-size: 12px; font-weight: 700; }
.arrow { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; }
.arrow.up { border-bottom: 7px solid currentColor; }
.arrow.down { border-top: 7px solid currentColor; }

.cashline b { color: var(--cream); font-weight: 800; }

.notice, .hint {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px); padding: 6px 12px;
  border-radius: 8px; font-weight: 700; font-size: 14px; text-align: center; pointer-events: none;
}
.notice { top: calc(var(--split) + var(--strip) / 2 + 30px); background: var(--cream); color: var(--crude); z-index: 3; }
.hint { background: rgba(21, 14, 10, .86); color: var(--cream); }
.idle {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--split) + var(--strip) / 2 + 30px); z-index: 3;
  width: max-content; max-width: calc(100% - 24px); padding: 6px 12px; border-radius: 8px;
  background: var(--red); color: var(--cream); font-weight: 800; font-size: 14px; pointer-events: none;
}
.idle.soon { background: rgba(21, 14, 10, .9); color: var(--down); }
.backbtn {
  position: absolute; right: 10px; bottom: calc(104px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); z-index: 4; min-height: 44px; padding: 8px 14px;
  border: 0; border-radius: 8px; background: var(--brass); color: var(--crude); font-weight: 800; font-size: 15px;
  box-shadow: 0 3px 0 var(--brass-deep);
}
.hint-race { top: 74px; }
.hint-grid { bottom: calc(106px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: var(--brass); color: var(--crude); }
[hidden] { display: none !important; }
#stage:not([data-phase='playing']) :is(.strip, .cashline, .standing, #pause, .biasbar, .backbtn) { visibility: hidden; }
#stage[data-phase='paused'] #pause { visibility: hidden; }

/* Title, end and pause screens keep the split: words in the sky, details underground. */
.screen { position: absolute; inset: 0; display: grid; grid-template-rows: calc(var(--split) - var(--strip) / 2) 1fr; z-index: 5; }
.topbar { z-index: 6; }
.screen-top { display: flex; align-items: flex-start; justify-content: center; padding: 7vh 16px 0; text-align: center; }
.screen-bottom {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 16px 22px calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  background: rgba(21, 14, 10, .93); border-top: 5px solid #8a5a33; text-align: center;
}
.end .screen-top, .paused .screen-top { padding-top: 48px; }
h1 {
  font-family: var(--display); font-weight: 400; color: var(--crude);
  font-size: min(16.5vw, 10dvh, 74px); line-height: .95;
  text-shadow: 0 2px 0 var(--brass), 0 4px 0 var(--brass-deep);
}
h2 { font-family: var(--display); font-weight: 400; color: var(--crude); font-size: min(9.5vw, 6dvh, 42px); line-height: 1.05; text-shadow: 0 2px 0 var(--brass); }
.lede { font-size: 18px; font-weight: 700; max-width: 32ch; }
.rules { list-style: none; display: grid; gap: 5px; font-size: 14px; text-align: left; max-width: 38ch; color: #ddcfb6; }
.rules b { color: var(--brass); font-weight: 800; }
.best { color: var(--muted); font-size: 14px; }
.btn {
  border: 0; border-radius: 8px; padding: 13px 28px 14px; min-height: 52px;
  background: var(--brass); color: var(--crude);
  font-weight: 900; font-size: 19px;
  box-shadow: 0 5px 0 var(--brass-deep);
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--brass-deep); }
.btn:disabled { opacity: .55; cursor: progress; }
.finalplace { font-size: 18px; font-weight: 700; }
.finalplace b { font-family: var(--display); font-weight: 400; font-size: 52px; color: var(--brass); line-height: 1; }
.newbest { color: var(--up); font-weight: 800; margin-top: -8px; }
.tally { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; text-align: left; min-width: 250px; }
.tally dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.tally dd { font-size: 18px; font-weight: 800; }

.rotate {
  display: none; position: absolute; inset: 0; z-index: 9;
  align-items: center; justify-content: center;
  background: var(--crude); font-size: 18px; font-weight: 700; padding: 20px; text-align: center;
}
@media (orientation: landscape) and (max-height: 480px) {
  #stage { width: 100vw; }
  .rotate { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  .stat b.pulse { animation: none; }
}

/* --- title menu --- */
.source { margin-top: -6px; font-size: 13px; font-weight: 700; color: var(--up); }
.source::before { content: ''; display: inline-block; width: 7px; height: 7px; margin: 0 6px 1px 0; border-radius: 50%; background: currentColor; }
.source.offline { color: var(--muted); }
.source:empty { display: none; }
.record { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 26px; text-align: center; }
.record dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.record dd { font-size: 17px; font-weight: 800; }
.titlelinks { display: flex; gap: 10px; }
.linkbtn {
  min-height: 44px; padding: 8px 16px; border: 2px solid #5c3820; border-radius: 8px;
  background: transparent; color: var(--cream); font-weight: 800; font-size: 15px; touch-action: manipulation;
}
.linkbtn:active { background: #3a2819; }
.hint-bias { bottom: calc(106px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); background: var(--brass); color: var(--crude); z-index: 3; animation: bob 1.2s ease-in-out infinite; }
.hint-bias::after, .hint-grid::after {
  content: ''; position: absolute; left: 50%; bottom: -7px; margin-left: -7px;
  border: 7px solid transparent; border-bottom: 0; border-top-color: var(--brass);
}
.hint-grid::after { display: none; }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

/* --- how to play --- */
.onboard {
  position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column;
  background: radial-gradient(120% 70% at 50% 0%, #3a2214 0%, var(--crude) 70%);
  padding: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)) 0 var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  animation: obIn .35s ease-out;
}
@keyframes obIn { from { opacity: 0; transform: translateY(16px); } }
.obtop { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px 0; }
.obcount { font-size: 13px; font-weight: 700; color: var(--muted); }
.obskip { border-color: transparent; color: var(--muted); }
.obtrack {
  flex: 1; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  scrollbar-width: none; touch-action: pan-x; overscroll-behavior: contain;
}
.obtrack::-webkit-scrollbar { display: none; }
.obslide {
  flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 8px 28px; text-align: center;
}
.obart { width: min(100%, 320px, 42dvh * 1.6); filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .45)); }
.obart svg { display: block; width: 100%; height: auto; border-radius: 14px; border: 3px solid #5c3820; font-family: var(--body); }
.obslide h2 { color: var(--brass); text-shadow: 0 2px 0 var(--brass-deep), 0 3px 0 #000; margin-top: 6px; }
.obslide p { font-size: 17px; font-weight: 600; max-width: 30ch; color: var(--cream); line-height: 1.4; }
.obslide p b { color: var(--brass); }
.obslide .obsmall { font-size: 14px; font-weight: 600; color: var(--muted); }
.obpulse { animation: obPulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes obPulse { 50% { transform: scale(1.12); } }
.obfoot { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 10px 22px 22px; }
.obfoot .btn { width: min(100%, 320px); }
.obdots { display: flex; gap: 8px; }
.obdots i { width: 8px; height: 8px; border-radius: 4px; background: #5c3820; transition: width .25s, background .25s; }
.obdots i.on { width: 24px; background: var(--brass); }

/* --- settings --- */
.sheet {
  position: absolute; inset: 0; z-index: 8; display: flex; align-items: flex-end;
  background: rgba(10, 6, 4, .6); animation: fade .2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheetcard {
  width: 100%; display: flex; flex-direction: column; gap: 10px;
  padding: 22px 20px calc(20px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  background: var(--crude-2); border-top: 5px solid #8a5a33; border-radius: 18px 18px 0 0;
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(40px); } }
.sheetcard h2 { color: var(--brass); text-shadow: 0 2px 0 var(--brass-deep); margin-bottom: 4px; }
.toggle, .rowbtn {
  display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 0 14px;
  border: 0; border-radius: 10px; background: #3a2819; font-size: 17px; font-weight: 800; text-align: left;
}
.rowbtn.danger { color: var(--down); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { position: relative; width: 50px; height: 30px; border-radius: 15px; background: #5c3820; transition: background .2s; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--cream); transition: transform .2s; }
.toggle input:checked + i { background: var(--up); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle input:focus-visible + i { outline: 3px solid #fff; outline-offset: 2px; }
.about { font-size: 13px; color: var(--muted); line-height: 1.45; padding: 4px 2px; }
.sheetcard .btn { margin-top: 4px; }

.end .screen-bottom .linkbtn, .paused .screen-bottom .linkbtn { margin-top: -4px; }

/* Inside the app there is no browser around the game, so the stage fills the phone. */
html[data-platform='ios'] #stage, html[data-platform='android'] #stage { width: 100vw; }
.topbar { padding-top: max(8px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))); top: 0; }
@media (prefers-reduced-motion: reduce) {
  .onboard, .sheet, .sheetcard, .hint-bias, .obpulse { animation: none; }
}
.obrun { animation: obRun 2.4s ease-in-out infinite; }
@keyframes obRun { 0% { transform: translateX(-30px); } 60%, 100% { transform: translateX(22px); } }
.onboard .btn:focus:not(:focus-visible) { outline: none; }
@media (prefers-reduced-motion: reduce) { .obrun { animation: none; } }
