:root {
  color-scheme: dark;
  --ink: #fff8db;
  --muted: #c8c2b6;
  --panel: rgba(18, 22, 31, 0.82);
  --line: #080a0f;
  --gold: #ffd35a;
  --start-bg: url("sprites/start_bg.png");
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #10151d;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  overflow-x: hidden;
}

button,
textarea,
select,
input {
  font: inherit;
}

.app {
  width: min(1120px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 28px 0;
}

.hidden {
  display: none !important;
}

.asset-debug {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  max-height: 34vh;
  overflow: auto;
  padding: 12px;
  color: #fff8db;
  border: 2px solid #ffd35a;
  border-radius: 8px;
  background: rgba(8, 10, 15, 0.92);
  font: 13px Consolas, monospace;
  white-space: pre-wrap;
}

.screen {
  width: min(960px, 100%);
}

.menu-screen,
.select-screen {
  position: relative;
  min-height: 620px;
  border: 4px solid var(--line);
  box-shadow: 0 0 0 4px #3b4354, 0 18px 0 rgba(0, 0, 0, 0.35);
  overflow: visible;
}

.menu-screen::before,
.select-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: var(--start-bg);
  background-size: auto 100%;
  background-position: 0 center;
  background-repeat: repeat-x;
  animation: bgPan 52s linear infinite;
}

.menu-screen::after,
.select-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(180deg, rgba(8, 11, 17, 0.12), rgba(8, 11, 17, 0.68));
}

@keyframes bgPan {
  from {
    background-position: 0 center;
  }
  to {
    background-position: -1500px center;
  }
}

.reduced-motion-bg .menu-screen::before,
.reduced-motion-bg .select-screen::before {
  animation-play-state: paused;
}

.title-wrap {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 2;
  width: min(880px, calc(100% - 20px));
  transform: translate(-50%, -34%);
  text-align: center;
}

.game-logo {
  width: 100%;
  max-height: 310px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.52));
}

h1,
h2 {
  margin: 0;
  color: #fff5be;
  font-size: clamp(44px, 8vw, 86px);
  line-height: 0.95;
  text-shadow: 0 5px 0 #9b382d, 0 9px 0 #090b10;
}

h2 {
  margin-bottom: 22px;
  font-size: clamp(34px, 5vw, 58px);
}

.home-actions {
  position: relative;
  z-index: 1;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 210px 24px 64px;
}

.image-menu-btn {
  width: min(460px, 72vw);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 14px rgba(255, 211, 90, 0.16));
  transition: transform 140ms ease, filter 140ms ease;
}

.secondary-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.image-menu-btn.small {
  width: min(250px, 34vw);
}

.image-menu-btn:hover,
.image-menu-btn:focus-visible {
  outline: none;
  transform: translateY(-6px) scale(1.03);
  filter: drop-shadow(0 14px 0 rgba(0, 0, 0, 0.48)) drop-shadow(0 0 22px rgba(255, 211, 90, 0.3));
}

.image-menu-btn:active {
  transform: translateY(2px) scale(0.99);
}

.image-menu-btn img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.glass-btn {
  min-height: 52px;
  padding: 0 24px;
  color: #12151d;
  border: 2px solid rgba(255, 255, 255, 0.38);
  border-bottom: 5px solid rgba(128, 82, 22, 0.85);
  border-radius: 8px;
  background: rgba(255, 211, 90, 0.78);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(4px);
  cursor: pointer;
  font-weight: 900;
}

.glass-btn.alt {
  color: var(--ink);
  background: rgba(45, 54, 74, 0.72);
}

.glass-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.panel {
  padding: 28px;
  border: 4px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0 0 4px #3b4354, 0 18px 0 rgba(0, 0, 0, 0.35);
}

.select-screen {
  padding: 28px;
  overflow: hidden;
}

.select-screen > * {
  position: relative;
  z-index: 1;
}

.character-grid,
.track-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  min-height: 250px;
  padding: 16px;
  color: var(--ink);
  border: 3px solid #0b0e15;
  border-radius: 8px;
  background: rgba(39, 45, 58, 0.86);
  text-align: left;
  cursor: pointer;
  backdrop-filter: blur(3px);
}

.card.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 3px rgba(255, 211, 90, 0.25);
}

.card canvas {
  width: 112px;
  height: 112px;
  margin-bottom: 12px;
  border: 3px solid #0d1119;
  background: #171b24;
  image-rendering: pixelated;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 24px;
}

.card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.race-screen {
  width: 100%;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.hud span,
.controls {
  min-height: 42px;
  padding: 10px 12px;
  border: 3px solid var(--line);
  background: #202633;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#gameCanvas {
  display: block;
  width: 100%;
  max-height: calc(100vh - 170px);
  border: 5px solid var(--line);
  background: #263f2b;
  image-rendering: pixelated;
}

.controls {
  margin-top: 10px;
  color: var(--muted);
}

.credits-text {
  width: 100%;
  min-height: 280px;
  margin-bottom: 18px;
  padding: 16px;
  color: var(--ink);
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #111720;
  line-height: 1.45;
  resize: vertical;
}

.settings-list {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 56px;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 38, 51, 0.86);
}

.setting-row select,
.setting-row input {
  min-width: 120px;
}

.result-list {
  margin: 22px 0;
  font-size: 22px;
}

@media (max-width: 780px) {
  .character-grid,
  .track-grid,
  .hud {
    grid-template-columns: 1fr;
  }

  .menu-screen,
  .select-screen {
    min-height: 560px;
  }

  .title-wrap {
    transform: translate(-50%, -26%);
  }

  .home-actions {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-top: 190px;
  }

  .image-menu-btn {
    width: min(390px, 100%);
    margin: 0 auto;
  }

  .secondary-actions {
    flex-direction: column;
    gap: 10px;
  }

  .image-menu-btn.small {
    width: min(320px, 92%);
  }
}
