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

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: radial-gradient(circle at top, #232b35 0%, #101318 55%, #07090c 100%);
  font-family: Arial, Helvetica, sans-serif;
  color: #fff;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.game-shell {
  width: 100vw;
  max-width: 430px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: rgba(7, 9, 12, 0.82);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f6c445;
}

.stats {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #d6d6d6;
}

.game {
  --sky-top: #7fd8ff;
  --sky-mid: #9be7ff;
  --sky-low: #f7d27a;
  --ground-top: #6f8b45;
  --ground-low: #2f4420;
  --sun-opacity: 1;
  --moon-opacity: 0;
  --stars-opacity: 0;
  --dusk-opacity: 0;
  --night-tint: 0;
  --time-darkness: 0;
  --skyline-speed: 18s;
  --cloud-speed: 24s;
  --mountain-speed: 30s;
  --tree-back-speed: 8s;
  --tree-front-speed: 4s;
  --landscape-speed: 18s;
  --floor-speed: 2.2s;
  position: relative;
  width: 100%;
  flex: 1;
  height: auto;
  min-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #171247;
  box-shadow: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 500ms linear;
}

.game::before {
  content: "";
  position: absolute;
  left: 54px;
  top: 50px;
  width: 46px;
  height: 46px;
  background:
    linear-gradient(#fff3a6 0 0) 8px 0 / 30px 8px no-repeat,
    linear-gradient(#fff3a6 0 0) 0 8px / 46px 30px no-repeat,
    linear-gradient(#fff3a6 0 0) 8px 38px / 30px 8px no-repeat;
  image-rendering: pixelated;
  opacity: var(--sun-opacity);
  filter: drop-shadow(0 0 16px rgba(255, 226, 118, 0.75));
  pointer-events: none;
  z-index: 1;
}

.game::after {
  content: "";
  position: absolute;
  right: 56px;
  top: 46px;
  width: 42px;
  height: 42px;
  background:
    linear-gradient(#e6f3ff 0 0) 8px 0 / 26px 8px no-repeat,
    linear-gradient(#e6f3ff 0 0) 0 8px / 34px 26px no-repeat,
    linear-gradient(#e6f3ff 0 0) 8px 34px / 26px 8px no-repeat,
    linear-gradient(var(--sky-top) 0 0) 22px 8px / 20px 24px no-repeat;
  image-rendering: pixelated;
  opacity: var(--moon-opacity);
  filter: drop-shadow(0 0 14px rgba(214, 239, 255, 0.55));
  pointer-events: none;
  z-index: 1;
}

.landscape,
.skyline,
.clouds,
.mountains,
.trees-back,
.road,
.trees-front,
.floor-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.landscape {
  background-image: url("../assets/backgrounds/pixel-sun-landscape-hq.png");
  background-repeat: repeat-x;
  background-size: auto 100%;
  background-position: 0 0;
  animation: scrollLandscape var(--landscape-speed) linear infinite;
  image-rendering: pixelated;
  z-index: 1;
  opacity: 1;
  transition: opacity 2400ms linear;
}

.landscape::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      rgba(7, 10, 38, calc(var(--time-darkness) * 0.35)),
      rgba(3, 5, 19, calc(var(--time-darkness) * 0.68))
  );
  mix-blend-mode: multiply;
}

.landscape-next {
  opacity: 0;
  z-index: 2;
}

.landscape-next.is-visible {
  opacity: 1;
}

.skyline {
  background-image:
    linear-gradient(rgba(255, 255, 210, var(--stars-opacity)) 0 0),
    linear-gradient(rgba(255, 255, 210, calc(var(--stars-opacity) * 0.7)) 0 0),
    linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0 2px, transparent 2px 34px);
  background-position: 18px 24px, 58px 48px, 0 0;
  background-size: 3px 3px, 2px 2px, 96px 100%;
  background-repeat: repeat;
  animation: scrollBg var(--skyline-speed) linear infinite;
  opacity: 0;
  z-index: 2;
}

.clouds {
  top: 24px;
  height: 130px;
  background-image:
    linear-gradient(#ffffff 0 0),
    linear-gradient(#ffffff 0 0),
    linear-gradient(#ffffff 0 0),
    linear-gradient(#edf8ff 0 0),
    linear-gradient(#ffffff 0 0),
    linear-gradient(#ffffff 0 0),
    linear-gradient(#edf8ff 0 0);
  background-size:
    34px 12px,
    58px 18px,
    30px 12px,
    82px 10px,
    28px 10px,
    50px 16px,
    72px 10px;
  background-position:
    28px 32px,
    58px 20px,
    110px 34px,
    34px 48px,
    245px 70px,
    272px 58px,
    230px 84px;
  background-repeat: repeat-x;
  animation: scrollBg var(--cloud-speed) linear infinite;
  image-rendering: pixelated;
  opacity: 0;
  z-index: 2;
}

.mountains {
  top: 115px;
  height: 180px;
  background:
    linear-gradient(135deg, transparent 0 43%, rgba(80, 121, 104, 0.42) 43% 54%, transparent 54%),
    linear-gradient(45deg, transparent 0 42%, rgba(185, 216, 164, 0.24) 42% 52%, transparent 52%),
    linear-gradient(90deg, rgba(63, 113, 67, 0.16) 0 42px, transparent 42px 80px);
  background-size: 360px 170px, 520px 170px, 160px 170px;
  animation: scrollBg var(--mountain-speed) linear infinite;
  opacity: 0;
  z-index: 2;
}

.trees-back,
.trees-front {
  image-rendering: pixelated;
  background-repeat: repeat-x;
}

.trees-back {
  top: 210px;
  height: 150px;
  background-image:
    linear-gradient(#2f6f45 0 0),
    linear-gradient(#3f8a51 0 0),
    linear-gradient(#2a5131 0 0),
    linear-gradient(#5a3922 0 0),
    linear-gradient(#2f6f45 0 0),
    linear-gradient(#3f8a51 0 0),
    linear-gradient(#2a5131 0 0),
    linear-gradient(#5a3922 0 0);
  background-size:
    34px 18px,
    52px 26px,
    38px 18px,
    10px 42px,
    28px 16px,
    44px 22px,
    30px 15px,
    8px 34px;
  background-position:
    38px 32px,
    24px 44px,
    42px 66px,
    48px 82px,
    198px 46px,
    184px 58px,
    204px 78px,
    212px 92px;
  animation: scrollBg var(--tree-back-speed) linear infinite;
  opacity: 0;
  z-index: 3;
}

.road {
  top: 335px;
  background:
    linear-gradient(100deg, transparent 0 18%, rgba(255, 232, 151, 0.38) 18% 21%, transparent 21% 100%),
    linear-gradient(80deg, transparent 0 78%, rgba(255, 232, 151, 0.32) 78% 81%, transparent 81% 100%),
    linear-gradient(180deg, #7d5c37 0%, #4c3320 58%, #24170f 100%);
  clip-path: polygon(18% 0, 82% 0, 100% 100%, 0 100%);
  opacity: 0;
  z-index: 3;
}

.trees-front {
  top: 272px;
  height: 190px;
  background-image:
    linear-gradient(#1e5d35 0 0),
    linear-gradient(#2f7b41 0 0),
    linear-gradient(#174328 0 0),
    linear-gradient(#4c2d1d 0 0),
    linear-gradient(#1f6237 0 0),
    linear-gradient(#39884b 0 0),
    linear-gradient(#174328 0 0),
    linear-gradient(#4c2d1d 0 0);
  background-size:
    44px 22px,
    68px 34px,
    48px 22px,
    14px 68px,
    34px 18px,
    58px 28px,
    40px 20px,
    12px 58px;
  background-position:
    96px 28px,
    78px 48px,
    104px 82px,
    116px 108px,
    305px 48px,
    288px 66px,
    310px 98px,
    320px 120px;
  animation: scrollBg var(--tree-front-speed) linear infinite;
  opacity: 0;
  z-index: 4;
}

.floor-lines {
  top: 350px;
  background-image:
    linear-gradient(rgba(255, 218, 114, 0.2), rgba(255, 218, 114, 0)),
    repeating-linear-gradient(90deg, rgba(246, 196, 69, 0.28) 0 70px, transparent 70px 160px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 18px);
  animation: scrollBg var(--floor-speed) linear infinite;
  opacity: 0;
  z-index: 5;
}

.time-tint {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 112, 45, var(--dusk-opacity)), rgba(4, 10, 27, var(--night-tint)));
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 3;
}

@keyframes scrollBg {
  from { background-position-x: 0; }
  to { background-position-x: -1000px; }
}

@keyframes scrollLandscape {
  from { background-position-x: 0; }
  to { background-position-x: -2172px; }
}

.lane-line {
  position: absolute;
  left: 0;
  width: 100%;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 4;
}

.lane-line {
  opacity: 0;
}

.lane-line.lane-top { top: 54%; }
.lane-line.lane-mid { top: 69%; }
.lane-line.lane-bottom { top: 76%; }

.karateka {
  position: absolute;
  left: 28%;
  width: 68px;
  height: 96px;
  transform: translateX(-50%);
  z-index: 8;
  transition: top 0.12s ease-out;
}

.karateka-sprite {
  position: absolute;
  inset: -18px -22px -10px -18px;
  width: calc(100% + 40px);
  height: calc(100% + 28px);
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0;
  pointer-events: none;
}

.karateka.has-sprite .karateka-sprite {
  opacity: 1;
}

.karateka.has-sprite .head,
.karateka.has-sprite .body,
.karateka.has-sprite .arm,
.karateka.has-sprite .leg {
  display: none;
}

.karateka .head {
  width: 30px;
  height: 30px;
  background: #f1c29a;
  border-radius: 50%;
  margin: 0 auto 3px;
  border: 3px solid #151515;
}

.karateka .body {
  width: 48px;
  height: 48px;
  background: #f8f8f8;
  border: 3px solid #151515;
  border-radius: 8px;
  margin: 0 auto;
  position: relative;
}

.karateka .belt {
  position: absolute;
  left: -4px;
  right: -4px;
  top: 22px;
  height: 8px;
  background: #111;
  border-radius: 8px;
}

.karateka .arm,
.karateka .leg {
  position: absolute;
  background: #f8f8f8;
  border: 3px solid #151515;
  border-radius: 12px;
  transform-origin: center top;
}

.karateka .arm.left {
  width: 18px;
  height: 46px;
  left: 4px;
  top: 40px;
  transform: rotate(28deg);
}

.karateka .arm.right {
  width: 18px;
  height: 46px;
  right: 4px;
  top: 40px;
  transform: rotate(-28deg);
}

.karateka .leg.left {
  width: 20px;
  height: 46px;
  left: 20px;
  top: 78px;
  transform: rotate(10deg);
}

.karateka .leg.right {
  width: 20px;
  height: 46px;
  right: 20px;
  top: 78px;
  transform: rotate(-10deg);
}

.karateka.punch .arm.right {
  width: 64px;
  height: 18px;
  right: -42px;
  top: 49px;
  transform: rotate(0deg);
  background: #fff;
}

.karateka.kick .leg.right,
.karateka.sweep .leg.right {
  width: 66px;
  height: 20px;
  right: -44px;
  top: 86px;
  transform: rotate(-8deg);
  background: #fff;
}

.karateka.jumpkick .leg.right {
  width: 66px;
  height: 20px;
  right: -44px;
  top: 36px;
  transform: rotate(-18deg);
  background: #fff;
}

.enemy {
  position: absolute;
  right: -80px;
  width: 48px;
  height: 48px;
  z-index: 7;
}

.enemy-sprite {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.enemy.bird {
  width: 46px;
  height: 46px;
}

.enemy.ninja {
  width: 46px;
  height: 46px;
}

.enemy.snake {
  width: 50px;
  height: 38px;
}

.enemy .head {
  width: 17px;
  height: 17px;
  background: #d9a270;
  border-radius: 50%;
  border: 2px solid #101010;
  margin: 0 auto 2px;
}

.enemy .body {
  width: 26px;
  height: 30px;
  border-radius: 6px;
  margin: 0 auto;
  background: #d94848;
  border: 2px solid #101010;
}

.enemy .legs {
  width: 23px;
  height: 11px;
  margin: -2px auto 0;
  border-left: 6px solid #101010;
  border-right: 6px solid #101010;
}

.enemy.top .body { background: #7cc4ff; }
.enemy.mid .body { background: #f6c445; }
.enemy.bottom .body { background: #d94848; }

.hit-text {
  position: absolute;
  z-index: 9;
  color: #f6c445;
  font-weight: 900;
  font-size: 22px;
  pointer-events: none;
  animation: pop 550ms ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

@keyframes pop {
  from { opacity: 1; transform: translateY(0) scale(0.8); }
  to { opacity: 0; transform: translateY(-42px) scale(1.25); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 9, 12, 0.58);
  backdrop-filter: blur(5px);
}

.panel {
  width: min(380px, 100%);
  background: rgba(21, 27, 35, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.5);
}

.panel h1,
.panel h2 {
  margin-bottom: 12px;
  color: #f6c445;
  line-height: 1.1;
}

.panel p {
  color: #d8d8d8;
  line-height: 1.45;
  margin-bottom: 12px;
}

.ranking-message {
  min-height: 20px;
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 16px 0;
}

.key {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  background: #f6c445;
  color: #111;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

button:hover {
  filter: brightness(1.05);
}

input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  margin: 7px 0;
  outline: none;
}

input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.scoreboards {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.board {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 12px;
  min-height: 110px;
}

.board h3 {
  color: #f6c445;
  font-size: 14px;
  margin-bottom: 8px;
}

.board ol {
  padding-left: 18px;
  font-size: 12px;
  color: #ddd;
  line-height: 1.7;
}

.board a {
  color: #9fd5ff;
  text-decoration: none;
}

.hidden {
  display: none;
}

.mobile-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: rgba(7, 9, 12, 0.9);
}

.mobile-buttons button {
  margin: 0;
  border-radius: 16px;
  padding: 12px 8px;
  font-size: 13px;
  opacity: 0.82;
}

@media (max-width: 720px) {
  body { align-items: flex-start; }
  .game-shell { width: 100vw; max-width: 430px; }
  .top-bar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .brand { font-size: 13px; }
  .stats { width: 100%; justify-content: space-between; }
  .game {
    height: auto;
    min-height: 0;
    max-height: none;
  }
  .scoreboards { grid-template-columns: 1fr; }
  .panel h1 { font-size: 26px; }
  .panel p { font-size: 14px; }
  .key { font-size: 12px; }
}

@media (max-width: 390px) {
  .game {
    height: auto;
    min-height: 0;
  }
  .mobile-buttons button {
    padding: 14px 6px;
    font-size: 13px;
  }
}
