* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  height: 100%;
  width: 100%;
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  margin: 0;
  overflow: hidden;
  background: #0a1018;
  color: #fff9ec;
  font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

.shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 14px;
  background:
    radial-gradient(circle at 18% 12%, rgba(118, 231, 199, 0.22), transparent 24%),
    radial-gradient(circle at 84% 18%, rgba(255, 209, 102, 0.16), transparent 26%),
    linear-gradient(135deg, #0d1722 0%, #14383b 47%, #311d37 100%);
}

.game-wrap {
  position: relative;
  width: min(100%, 1120px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(255, 249, 236, 0.26);
  border-radius: 8px;
  background: #87cfef;
  box-shadow:
    0 30px 100px rgba(0, 0, 0, 0.56),
    0 0 0 1px rgba(118, 231, 199, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#game,
#game canvas {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  touch-action: none;
  overscroll-behavior: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  pointer-events: none;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.character-select {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.character-button {
  min-width: 72px;
  height: 36px;
  border: 2px solid rgba(255, 249, 236, 0.55);
  border-radius: 8px;
  background: rgba(10, 16, 24, 0.42);
  color: #fff9ec;
  font: 900 14px/1 "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(9, 15, 22, 0.28);
  text-shadow: 0 2px 0 rgba(9, 15, 22, 0.75);
  touch-action: manipulation;
}

.character-button.is-active {
  border-color: rgba(255, 209, 102, 0.95);
  background: rgba(255, 209, 102, 0.28);
  color: #fff9ec;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.life {
  color: #fff9ec;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  text-shadow:
    0 2px 0 rgba(22, 32, 42, 0.95),
    0 0 10px rgba(22, 32, 42, 0.72);
}

.sound-button {
  width: 42px;
  height: 38px;
  border: 2px solid rgba(255, 249, 236, 0.55);
  border-radius: 8px;
  background: rgba(10, 16, 24, 0.42);
  color: #fff9ec;
  font: 900 19px/1 system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(9, 15, 22, 0.28);
  text-shadow: 0 2px 0 rgba(9, 15, 22, 0.75);
  touch-action: manipulation;
}

.sound-button.is-muted {
  border-color: rgba(255, 120, 166, 0.9);
  background: rgba(255, 120, 166, 0.24);
}

.sound-button:active {
  transform: translateY(2px);
}

.touch-controls {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: none;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
  z-index: 6;
}

.touch-pad {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-pad.dpad,
.touch-pad.diamond-pad {
  position: relative;
  width: clamp(168px, 24vw, 250px);
  height: clamp(168px, 24vw, 250px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(5px, 1vw, 10px);
}

.touch-pad button {
  width: clamp(56px, 7.4vw, 82px);
  height: clamp(56px, 7.4vw, 82px);
  border: 2px solid rgba(255, 249, 236, 0.62);
  border-radius: 11px;
  background: rgba(10, 16, 24, 0.46);
  color: #fff9ec;
  font-size: clamp(22px, 4.2vw, 34px);
  font-weight: 900;
  line-height: 1;
  box-shadow:
    0 12px 34px rgba(9, 15, 22, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  text-shadow: 0 2px 0 rgba(9, 15, 22, 0.8);
  touch-action: none;
}

.dpad button,
.diamond-pad button {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.dpad::before {
  content: "";
  grid-column: 2;
  grid-row: 2;
  border-radius: 10px;
  background: rgba(10, 16, 24, 0.28);
  box-shadow: inset 0 0 0 2px rgba(255, 249, 236, 0.22);
}

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

#leftBtn {
  grid-column: 1;
  grid-row: 2;
}

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

#rightBtn {
  grid-column: 3;
  grid-row: 2;
}

.diamond-pad {
  transform: perspective(420px) rotateX(8deg);
}

.diamond-pad button {
  border-radius: 14px 8px;
  background: rgba(24, 25, 35, 0.5);
}

.action-top {
  grid-column: 2;
  grid-row: 1;
}

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

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

.action-bottom {
  grid-column: 2;
  grid-row: 3;
}

.touch-pad button:active {
  transform: translateY(2px);
  background: rgba(118, 231, 199, 0.34);
}

@media (hover: none), (pointer: coarse), (max-width: 820px) {
  .shell {
    padding: 0;
  }

  .game-wrap {
    width: 100vw;
    height: 100svh;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
  }

  .touch-controls {
    display: flex;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    align-items: end;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .character-button {
    min-width: 64px;
    height: 34px;
    font-size: 13px;
  }
}

@media (max-width: 520px), (max-height: 430px) {
  .touch-pad {
    gap: 8px;
  }

  .touch-pad.dpad,
  .touch-pad.diamond-pad {
    width: clamp(150px, 31vw, 190px);
    height: clamp(150px, 31vw, 190px);
  }

  .touch-pad button {
    font-size: clamp(22px, 6vw, 30px);
  }
}

@media (max-height: 390px) {
  .touch-pad.dpad,
  .touch-pad.diamond-pad {
    width: min(32vw, 160px);
    height: min(32vw, 160px);
  }

  .touch-controls {
    bottom: max(4px, env(safe-area-inset-bottom));
  }
}
