:root {
  --bg: #0b0b0c;
  --panel: rgba(13, 13, 15, 0.92);
  --panel-soft: rgba(20, 20, 23, 0.8);
  --panel-border: rgba(178, 143, 74, 0.5);
  --panel-inset: rgba(255, 232, 185, 0.08);
  --text-main: #f6efe1;
  --text-soft: rgba(246, 239, 225, 0.72);
  --gold: #d2a53c;
  --gold-bright: #f4c24f;
  --green: #25a14c;
  --green-bright: #6cdf69;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(47, 122, 67, 0.14), transparent 24%),
    linear-gradient(180deg, #1d1915 0%, #090909 100%);
  color: var(--text-main);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

button,
canvas,
img {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  width: 100%;
}

.game-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  width: min(100vw, 430px);
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    12px
    max(12px, env(safe-area-inset-bottom))
    12px;
}

#gameCanvas {
  width: min(100%, calc(100vh * 0.462), 390px);
  height: min(calc(100vh - 24px), 844px);
  max-width: 100%;
  max-height: calc(100vh - 24px);
  border-radius: 28px;
  background: #111214;
  box-shadow:
    0 32px 84px rgba(0, 0, 0, 0.54),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  inset: 0;
  width: 100%;
  pointer-events: none;
  z-index: 3;
}

.hud-stack {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: clamp(10px, 3vw, 18px);
  display: grid;
  gap: 10px;
}

.hud-panel,
.pause-button,
.screen-card {
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(39, 33, 28, 0.82), rgba(10, 10, 12, 0.94)),
    var(--panel);
  box-shadow:
    0 16px 38px rgba(0, 0, 0, 0.3),
    inset 0 0 0 1px var(--panel-inset);
}

.hud-panel {
  min-width: 118px;
  padding: 12px 14px;
  border-radius: 18px;
}

.hud-panel--logo {
  display: grid;
  place-items: center;
  padding: 10px;
}

.hud-emblem {
  display: block;
  width: 78px;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
}

.hud-label {
  display: block;
  color: var(--gold-bright);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-value {
  display: block;
  margin-top: 6px;
  color: var(--text-main);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.03em;
}

.hud-riders-head {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.hud-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  image-rendering: pixelated;
}

.hud-value--riders {
  color: var(--green-bright);
}

.pause-button {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: clamp(10px, 3vw, 18px);
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 18px;
  cursor: pointer;
}

.pause-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  image-rendering: pixelated;
}

.overlay,
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at top, rgba(48, 125, 66, 0.18), transparent 26%),
    rgba(4, 4, 5, 0.82);
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}

.overlay--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.level-toast {
  position: fixed;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 52px));
  left: 50%;
  width: auto;
  max-width: calc(var(--road-width, 278px) - 18px);
  inset-inline: auto;
  z-index: 12;
  display: block;
  padding: 0;
  background: none;
  pointer-events: none;
  transform: translateX(-50%);
  transition:
    opacity 280ms ease,
    visibility 280ms ease;
}

.level-toast__content {
  min-height: 0;
  width: auto;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  transform: translateY(8px);
  opacity: 0;
  text-align: center;
  box-sizing: border-box;
}

.level-toast:not(.level-toast--fullclub) .level-win-media,
.level-toast:not(.level-toast--fullclub) .level-toast__copy {
  display: none;
}

.level-toast:not(.level-toast--fullclub) .level-toast__meta {
  margin: 0 0 4px;
  color: rgba(119, 235, 109, 0.94);
  font-size: clamp(11px, 3.2vw, 13px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-wrap: balance;
  text-shadow:
    0 2px 10px rgba(0, 0, 0, 0.92),
    0 0 18px rgba(0, 0, 0, 0.5);
}

.level-toast:not(.level-toast--fullclub) .level-toast__title {
  margin: 0;
  color: rgba(246, 239, 225, 0.98);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.01em;
  text-wrap: balance;
  text-shadow:
    0 2px 10px rgba(0, 0, 0, 0.9),
    0 0 18px rgba(0, 0, 0, 0.55),
    0 0 28px rgba(54, 183, 88, 0.15);
}

.level-toast:not(.level-toast--fullclub):not(.overlay--hidden) .level-toast__content {
  animation: level-text-fade 3.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.level-win-media {
  display: none;
  width: min(72vw, 228px);
  height: auto;
  margin: 0 auto 12px;
  border-radius: 20px;
  box-shadow:
    0 16px 42px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.05);
}

.level-toast--fullclub {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(calc(var(--playfield-width, 390px) - 12px), 360px);
  max-width: min(calc(var(--playfield-width, 390px) - 12px), 360px);
}

.level-toast--fullclub .level-toast__content {
  padding: 18px 18px 20px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(24, 20, 16, 0.88), rgba(7, 7, 9, 0.92)),
    rgba(10, 10, 12, 0.82);
  box-shadow:
    0 24px 52px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(210, 165, 60, 0.24),
    0 0 30px rgba(54, 183, 88, 0.18);
}

.level-toast--fullclub:not(.overlay--hidden) .level-toast__content {
  animation: full-club-pop 4.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.level-toast--fullclub .level-win-media {
  display: block;
}

.level-toast--fullclub .level-toast__meta {
  margin-bottom: 6px;
  font-size: 11px;
  color: rgba(244, 194, 79, 0.94);
}

.level-toast--fullclub .level-toast__title {
  font-size: clamp(22px, 6vw, 32px);
  line-height: 1.05;
}

.level-toast--fullclub .level-toast__copy {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.42;
  color: rgba(246, 239, 225, 0.9);
}

.level-toast:not(.level-toast--fullclub) .level-toast__content {
  opacity: 1;
}

.level-toast:not(.level-toast--fullclub) .level-toast__content,
.level-toast:not(.level-toast--fullclub) .level-toast__meta,
.level-toast:not(.level-toast--fullclub) .level-toast__title {
  background: none !important;
  box-shadow: none !important;
}

.screen-card {
  width: min(calc(100vw - 28px), 360px);
  padding: 24px 22px;
  border-radius: 28px;
  text-align: center;
}

.game-over-card {
  position: relative;
  overflow: hidden;
}

.game-over-media {
  display: none;
  width: 100%;
  height: auto;
  object-fit: cover;
  border-radius: 28px;
}

.game-over-content {
  position: relative;
  z-index: 1;
}

#gameOverOverlay.game-over-overlay--victory .game-over-card {
  width: min(calc(100vw - 24px), 392px);
  padding: 0;
  border-radius: 30px;
  background: #050505;
  box-shadow:
    0 26px 68px rgba(0, 0, 0, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

#gameOverOverlay.game-over-overlay--victory .game-over-media {
  display: block;
}

#gameOverOverlay.game-over-overlay--victory .game-over-content {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  padding: 14px 14px 16px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(18, 16, 14, 0.52), rgba(8, 8, 10, 0.74)),
    rgba(8, 8, 10, 0.48);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.28),
    inset 0 0 0 1px rgba(242, 199, 92, 0.14);
  backdrop-filter: blur(8px);
}

#gameOverOverlay.game-over-overlay--victory #gameOverLogo,
#gameOverOverlay.game-over-overlay--victory #gameOverKicker,
#gameOverOverlay.game-over-overlay--victory #gameOverTitle,
#gameOverOverlay.game-over-overlay--victory #gameOverScore,
#gameOverOverlay.game-over-overlay--victory #gameOverLevel,
#gameOverOverlay.game-over-overlay--victory #gameOverRiders {
  display: none;
}

#gameOverOverlay.game-over-overlay--victory #restartButton {
  width: 100%;
  margin-top: 0;
  min-height: 56px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(230, 191, 85, 0.98), rgba(181, 126, 36, 0.98));
  color: #17130f;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 244, 212, 0.42);
}

.level-toast__content {
  width: 100%;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.screen-card--menu {
  padding-top: 28px;
}

.screen-logo {
  display: block;
  margin: 0 auto 14px;
  width: min(72vw, 210px);
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
}

.screen-logo--large {
  width: min(78vw, 240px);
}

.screen-logo--small {
  width: min(52vw, 150px);
}

.screen-kicker {
  margin: 0;
  color: var(--green-bright);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.screen-title {
  margin: 8px 0 10px;
  color: var(--text-main);
  font-size: clamp(28px, 4vw, 34px);
  line-height: 1.02;
}

.screen-copy {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.52;
}

.menu-hint {
  margin: 14px 0 0;
  color: rgba(246, 239, 225, 0.68);
  font-size: 12px;
  line-height: 1.5;
}

.screen-copy--stats + .screen-copy--stats {
  margin-top: 8px;
}

.progress-track {
  width: 100%;
  height: 12px;
  margin-top: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold-bright));
  transition: width 140ms ease;
}

.progress-value {
  margin: 10px 0 0;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
}

.button-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

.primary-button,
.secondary-button {
  min-width: 132px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.primary-button {
  background: linear-gradient(180deg, #2fb75a, #16813c);
  color: #f4f1e8;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text-main);
}

.touch-hint {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  gap: 18px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(6, 6, 7, 0.54);
  color: rgba(246, 239, 225, 0.52);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transform: translateX(-50%);
  pointer-events: none;
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.touch-hint--hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

@keyframes level-toast-pop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }

  10% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  82% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(24px) scale(0.98);
  }
}

@keyframes level-text-fade {
  0% {
    opacity: 0;
    transform: translateY(14px);
  }

  12% {
    opacity: 1;
    transform: translateY(0);
  }

  82% {
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes full-club-pop {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.92);
  }

  10% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  84% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
}

@media (max-width: 440px) {
  .level-toast {
    width: auto;
    max-width: calc(var(--road-width, 278px) - 12px);
  }

  .hud-panel {
    min-width: 104px;
    padding: 10px 12px;
  }

  .hud-emblem {
    width: 64px;
  }

  .hud-value {
    font-size: 22px;
  }

  .pause-button {
    width: 58px;
    height: 58px;
  }

}
