* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100%;
  background: #0b0d1a;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#game-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
#game-wrap canvas {
  display: block;
  touch-action: none;
}
#hint {
  position: fixed;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: #888;
  pointer-events: none;
  user-select: none;
}

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0
    max(16px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  pointer-events: none;
  touch-action: none;
}

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}

.touch-cluster-move {
  align-items: center;
}

.touch-cluster-action {
  gap: 12px;
}

.touch-column {
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 86px;
  height: 86px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  background: rgba(20, 20, 40, 0.48);
  color: #ffffff;
  font: 700 18px/1 "Courier New", monospace;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.28);
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-button-direction {
  font-size: 36px;
}

.touch-button-small {
  width: 64px;
  height: 64px;
  font-size: 28px;
}

.touch-button-action {
  width: 96px;
  height: 96px;
}

.touch-button.is-active {
  transform: translateY(4px);
  background: rgba(255, 200, 30, 0.58);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.24);
}

#rotate-hint {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 40;
  display: none;
  width: min(460px, calc(100vw - 32px));
  padding: 11px 16px;
  transform: translateX(-50%);
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 12px;
  background: rgba(11, 13, 26, 0.82);
  color: #ffffff;
  font: 700 16px/1.3 "Courier New", monospace;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.34);
  pointer-events: none;
  touch-action: none;
}

@media (any-pointer: coarse) {
  body.show-touch-controls #touch-controls {
    display: flex;
  }
}

@media (any-pointer: coarse) and (orientation: portrait) {
  #rotate-hint {
    display: block;
  }

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

  .touch-cluster {
    gap: 6px;
  }

  .touch-cluster-action {
    gap: 8px;
  }

  .touch-button {
    width: 62px;
    height: 62px;
    border-radius: 11px;
    font-size: 13px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
  }

  .touch-button-direction {
    font-size: 28px;
  }

  .touch-button-small {
    width: 48px;
    height: 48px;
    font-size: 22px;
  }

  .touch-button-action {
    width: 68px;
    height: 68px;
  }
}

@media (any-pointer: coarse) and (max-height: 520px) {
  #touch-controls {
    padding:
      0
      max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .touch-cluster {
    gap: 8px;
  }

  .touch-cluster-action {
    gap: 10px;
  }

  .touch-button {
    width: 74px;
    height: 74px;
    border-radius: 12px;
    font-size: 16px;
  }

  .touch-button-direction {
    font-size: 32px;
  }

  .touch-button-small {
    width: 56px;
    height: 56px;
    font-size: 25px;
  }

  .touch-button-action {
    width: 84px;
    height: 84px;
  }
}
