:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #080b10;
  color: #f5f7fb;
}

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(217, 67, 67, 0.22), transparent 28%),
    radial-gradient(circle at 82% 84%, rgba(40, 149, 132, 0.22), transparent 30%),
    linear-gradient(145deg, #080b10 0%, #15202a 52%, #0a0d12 100%);
}

button {
  font: inherit;
}

#game-shell {
  width: min(100vw, 620px);
  height: min(100vh, 960px);
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}

#hud {
  min-height: 74px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 9, 14, 0.72);
  backdrop-filter: blur(16px);
}

#hud div {
  display: grid;
  gap: 4px;
  justify-items: center;
}

#hud span {
  color: #a9b2bd;
  font-size: 0.98rem;
  font-weight: 700;
}

#hud strong {
  color: #ffffff;
  font-size: 1.58rem;
  font-weight: 900;
  letter-spacing: 0;
}

#stage-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #0c141c;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

#game-root,
#game-root canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(4, 7, 10, 0.68);
}

#overlay.visible {
  display: grid;
}

#overlay h1 {
  margin: 0;
  color: #fff4d6;
  font-size: clamp(2.8rem, 12vw, 5rem);
  line-height: 0.92;
  letter-spacing: 0;
  text-shadow: 0 4px 0 #9a2f2f;
}

#overlay p {
  margin: 0;
  color: #dce7ef;
  font-weight: 700;
}

#start-button {
  min-width: 128px;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  color: #081018;
  background: #ffd166;
  font-weight: 900;
  cursor: pointer;
}

#touch-controls {
  height: 140px;
  display: grid;
  place-items: center;
  pointer-events: auto;
}

#dpad {
  position: relative;
  width: 132px;
  height: 132px;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  place-content: center;
  gap: 0;
  touch-action: none;
  user-select: none;
}

#dpad::before {
  content: "";
  grid-column: 2;
  grid-row: 2;
  border-radius: 14px;
  background: rgba(5, 12, 22, 0.62);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.direction-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(125, 211, 252, 0.88);
  border-radius: 12px;
  color: #06101a;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(125, 211, 252, 0.9)),
    #7dd3fc;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 8px 20px rgba(0, 0, 0, 0.44);
  font-size: 1.22rem;
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  user-select: none;
}

.direction-button.active {
  transform: translateY(2px);
  background: linear-gradient(145deg, #ffd166, #38bdf8);
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.32),
    0 5px 14px rgba(0, 0, 0, 0.4);
}

.direction-up {
  grid-column: 2;
  grid-row: 1;
}

.direction-left {
  grid-column: 1;
  grid-row: 2;
}

.direction-right {
  grid-column: 3;
  grid-row: 2;
}

.direction-down {
  grid-column: 2;
  grid-row: 3;
}

@media (min-width: 740px) and (pointer: fine) {
  #touch-controls {
    display: none;
  }

  #game-shell {
    height: min(100vh, 900px);
  }
}

@media (max-width: 739px), (pointer: coarse) {
  #game-shell {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    gap: 0;
    grid-template-rows: 1fr;
  }

  #stage-wrap {
    grid-row: 1;
    border: 0;
    box-shadow: none;
  }

  #hud {
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    z-index: 5;
    min-height: 104px;
    border-width: 0 0 1px;
    background: rgba(6, 9, 14, 0.72);
  }

  #hud span {
    font-size: 1.18rem;
    line-height: 1.05;
  }

  #hud strong {
    font-size: 2.35rem;
    line-height: 1;
  }

  #touch-controls {
    position: fixed;
    right: 18px;
    bottom: max(18px, env(safe-area-inset-bottom, 0));
    z-index: 30;
    width: 164px;
    height: 164px;
    display: grid;
  }

  #dpad {
    width: 154px;
    height: 154px;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
  }

  .direction-button {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 1.42rem;
  }

  #overlay {
    padding: 96px 24px 108px;
  }

  #overlay h1 {
    font-size: clamp(4rem, 18vw, 6rem);
  }

  #overlay p {
    max-width: 15rem;
    font-size: 1.15rem;
    line-height: 1.45;
  }

  #start-button {
    min-width: 152px;
    min-height: 52px;
    font-size: 1.16rem;
  }
}
