:root {
  color-scheme: dark;
  --stage-width: 527px;
  --stage-height: 936px;
  --stage-scale: 1;
  --bg: #06070b;
  --panel: #151923;
  --panel-hi: #242a36;
  --panel-low: #090b10;
  --line: #48515f;
  --line-soft: #2b323e;
  --text: #f3f5f8;
  --muted: #929ba8;
  --yellow: #ffd51f;
  --yellow-deep: #c79600;
  --red: #f01e1e;
  --cyan: #2dd6e8;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background:
    linear-gradient(125deg, #151822 0%, #050609 46%, #20222b 100%);
  color: var(--text);
  font-family: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
}

button {
  font: inherit;
}

button:disabled {
  cursor: default;
  opacity: 0.48;
}

.arcade {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: var(--stage-width);
  height: var(--stage-height);
  min-height: 0;
  display: grid;
  grid-template-rows: 50px minmax(0, 1fr);
  align-content: start;
  gap: 6px;
  padding: 6px;
  overflow: hidden;
  transform: translateX(-50%) scale(var(--stage-scale));
  transform-origin: bottom center;
}

.marquee {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.marquee h1 {
  position: relative;
  margin: 0;
  min-width: 0;
  padding: 9px 0 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 1.22rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 2px 0 #000;
}

.marquee h1::after {
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 118px;
  height: 3px;
  background: var(--yellow);
  transform: translateX(-50%);
  content: "";
}

.flag {
  height: 24px;
  border: 1px solid #535b68;
  background:
    linear-gradient(90deg, transparent 0 16%, var(--yellow) 16% 54%, transparent 54% 100%),
    linear-gradient(180deg, #313947 0%, #0a0d13 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.flag-right {
  transform: scaleX(-1);
}

.game-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: 390px 58px minmax(0, 1fr);
  gap: 7px;
  padding: 8px;
  border: 1px solid #404958;
  background:
    linear-gradient(180deg, #242936 0%, #111620 46%, #07090e 100%);
  box-shadow:
    0 20px 52px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.82);
}

.screen {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 390px;
  min-height: 0;
  max-height: none;
  margin: 0 auto;
  border: 1px solid #090b10;
  background: #000;
  box-shadow:
    0 0 0 2px #384251,
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.12) 0,
    rgba(255, 255, 255, 0.12) 1px,
    transparent 1px,
    transparent 5px
  );
  mix-blend-mode: soft-light;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  pointer-events: none;
  text-align: center;
}

.overlay.is-hidden {
  display: none;
}

.start-button,
.race-button,
.bank-button,
.car-card,
.stake-button {
  border: 0;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  touch-action: manipulation;
}

.start-button {
  min-width: 144px;
  min-height: 42px;
  padding: 9px 20px;
  border: 1px solid rgba(255, 213, 31, 0.95);
  background:
    linear-gradient(105deg, var(--yellow) 0 18%, #f7a800 18% 100%);
  color: #050505;
  font-size: 1.02rem;
  font-weight: 900;
  letter-spacing: 0.07em;
  pointer-events: auto;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.status-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 0;
}

.status-board div {
  position: relative;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 8px 8px 7px;
  border: 1px solid var(--line-soft);
  background:
    linear-gradient(180deg, rgba(36, 42, 54, 0.98) 0%, rgba(8, 10, 15, 0.98) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.status-board div::before {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--yellow);
  content: "";
}

.status-board span {
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
}

.status-board strong {
  color: #ffffff;
  font-size: 1.04rem;
  font-weight: 900;
  line-height: 1;
  overflow-wrap: anywhere;
}

.betting-board {
  display: grid;
  grid-template-rows: 28px minmax(0, 1fr) 45px 49px;
  gap: 7px;
  min-height: 0;
  padding: 8px;
  border: 1px solid var(--line-soft);
  background:
    linear-gradient(180deg, rgba(24, 29, 39, 0.98), rgba(7, 9, 13, 0.98));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -1px 0 rgba(0, 0, 0, 0.88);
}

.car-grid,
.stake-row,
.race-actions {
  min-height: 0;
}

.panel-title {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 0 6px;
  border-bottom: 1px solid #303847;
  color: var(--text);
  font-size: 0.86rem;
}

.panel-title strong {
  display: inline-block;
  width: max-content;
  padding: 4px 10px 4px 8px;
  background: #f4f5f7;
  color: #07090d;
  font-weight: 900;
  letter-spacing: 0.07em;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

.panel-title span {
  padding: 4px 8px;
  background: var(--yellow);
  color: #050505;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}

.car-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.car-card {
  position: relative;
  display: grid;
  grid-template-rows: 15px 70px 1fr 15px;
  justify-items: center;
  align-items: center;
  gap: 3px;
  min-height: 112px;
  padding: 5px 3px;
  border: 1px solid #303847;
  background:
    linear-gradient(180deg, #1a202b 0%, #090c12 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -18px 26px rgba(0, 0, 0, 0.16);
}

.car-card::before {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 3px;
  background: var(--entry-color, var(--yellow));
  opacity: 0.85;
  content: "";
}

.entry-no {
  justify-self: start;
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-size: 0.54rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
}

.car-card strong {
  color: #ffffff;
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 #000;
}

.car-card span:last-child {
  color: var(--muted);
  font-size: 0.52rem;
  font-weight: 900;
  line-height: 1;
}

.car-card.is-active {
  border-color: var(--yellow);
  background:
    linear-gradient(180deg, rgba(52, 45, 22, 0.98) 0%, rgba(14, 12, 8, 0.98) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 213, 31, 0.26),
    0 0 0 1px rgba(255, 213, 31, 0.18);
}

.car-card.is-active::after {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background:
    linear-gradient(90deg, var(--yellow) 0 72%, var(--red) 72% 100%);
  content: "";
}

.car-swatch {
  position: relative;
  width: 70px;
  height: 70px;
  background-image: url("assets/cars/car-top-sheet.png");
  background-repeat: no-repeat;
  background-size: 500% 100%;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.68));
}

.car-swatch::before,
.car-swatch::after {
  display: none;
  content: "";
}

.stake-row,
.race-actions {
  display: grid;
  gap: 5px;
}

.stake-row {
  grid-template-columns: repeat(4, 1fr);
}

.stake-button {
  min-height: 45px;
  border: 1px solid #303847;
  color: #ffffff;
  background:
    linear-gradient(180deg, #202735 0%, #0b0e14 100%);
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.stake-button.is-active {
  border-color: var(--yellow);
  color: #050505;
  background:
    linear-gradient(180deg, #ffe766 0%, #f0b400 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.34),
    0 0 0 1px rgba(255, 213, 31, 0.18);
}

.race-actions {
  grid-template-columns: 1fr 0.58fr;
}

.race-button,
.bank-button {
  min-height: 49px;
  border: 1px solid #303847;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 0 #000;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.race-button {
  border-color: var(--yellow);
  color: #050505;
  background:
    linear-gradient(105deg, var(--yellow) 0 18%, #f2a900 18% 100%);
  text-shadow: none;
}

.bank-button {
  color: #dfe5ee;
  background:
    linear-gradient(180deg, #202735 0%, #0b0e14 100%);
}

.start-button:active,
.race-button:active,
.bank-button:active,
.car-card:active,
.stake-button:active {
  transform: translateY(1px);
  filter: brightness(0.92);
}

.start-button:active {
  transform: translateY(1px);
}

@media (hover: hover) {
  .start-button:hover,
  .race-button:hover,
  .bank-button:hover,
  .car-card:hover,
  .stake-button:hover {
    filter: brightness(1.12);
  }
}

body.is-desktop {
  background:
    radial-gradient(circle at 18% 18%, rgba(45, 214, 232, 0.16), transparent 30%),
    radial-gradient(circle at 82% 28%, rgba(255, 213, 31, 0.12), transparent 28%),
    linear-gradient(125deg, #151822 0%, #050609 44%, #20222b 100%);
}

body.is-desktop .arcade {
  bottom: 50%;
  gap: 8px;
  padding: 8px;
  grid-template-rows: 52px minmax(0, 1fr);
  transform: translate(-50%, 50%) scale(var(--stage-scale));
  transform-origin: center center;
}

body.is-desktop .marquee {
  grid-template-columns: 70px 1fr 70px;
  gap: 12px;
}

body.is-desktop .marquee h1 {
  font-size: 1.4rem;
}

body.is-desktop .flag {
  height: 28px;
}

body.is-desktop .game-shell {
  grid-template-columns: 720px 450px;
  grid-template-rows: 74px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
}

body.is-desktop .screen {
  grid-row: 1 / 3;
  width: 100%;
  height: 100%;
}

body.is-desktop .status-board {
  grid-template-columns: repeat(4, 1fr);
  grid-column: 2;
  grid-row: 1;
}

body.is-desktop .status-board div {
  padding: 9px 8px 8px;
}

body.is-desktop .status-board strong {
  font-size: 1.08rem;
}

body.is-desktop .betting-board {
  grid-column: 2;
  grid-row: 2;
  grid-template-rows: 32px minmax(0, 1fr) 54px 58px;
  gap: 8px;
  overflow: hidden;
}

body.is-desktop .panel-title {
  grid-template-columns: max-content minmax(0, 1fr);
  min-height: 32px;
  font-size: 0.92rem;
  overflow: hidden;
}

body.is-desktop .panel-title strong {
  white-space: nowrap;
}

body.is-desktop .panel-title span {
  justify-self: end;
  min-width: 104px;
  max-width: 154px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.is-desktop .car-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  overflow: hidden;
}

body.is-desktop .car-card {
  min-width: 0;
  grid-template-rows: 16px 72px minmax(20px, 1fr) 16px;
  min-height: 124px;
  padding: 5px 2px;
}

body.is-desktop .car-swatch {
  width: 72px;
  height: 72px;
}

body.is-desktop .car-card strong {
  font-size: 0.72rem;
}

body.is-desktop .stake-button {
  min-width: 0;
  min-height: 54px;
}

body.is-desktop .race-actions {
  grid-template-columns: minmax(0, 1.55fr) minmax(132px, 0.72fr);
}

body.is-desktop .race-button,
body.is-desktop .bank-button {
  min-width: 0;
  min-height: 58px;
  overflow: hidden;
  white-space: nowrap;
}
